How to set date_modified through REST API

I want to set the date_modified field of Notes that I am importing through the REST API. However, I can't see any way to turn off the automatic updating of date_modified in the REST API, if I try setting update_date_modified to false this has no effect.

An example of data I am sending via an HTTP PUT:

{
   "update_date_modified": false,
   "date_modified": "2016-02-09T10:12:52.0000000"
}

The request works but the date_modified is set to the date of the request, not the value I set

Parents
  • Hi

    Currently, you can not set/overwrite the date_modified to a certain value. The 'date_modified = false' will tell the SugarBean not to update the date_modified field only.

    If you want to do that then I would suggest using after save logic hook using DB query instead of SugarBean save function.

    Kind Regards,

    Junaid

  • Is that a recent change?

    I have done several custom imports of data from other systems in the past and wanted to preserve the modified/created dates and modified/created users


    Working directly with the bean I successfully used:   

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    //set a bunch of other values for the bean...
    //set the create and modified to the original record's values
    $tbean->date_entered = $orig_created_date;
    $tbean->date_modified = $orig_date_modified;
    $tbean->created_by = get_sugar_user_id($orig_create_user_name);
    $tbean->modified_by = get_sugar_user_id($orig_modified_user_name);
    //these flags prevent the save process from overriding created by and modified by
    $tbean->update_date_modified = false;
    $tbean->update_modified_by = false;
    $tbean->set_created_by = false;
    $tbean->update_date_entered = false;
    $tbean->save();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    FrancescaS

  • The statement was based on my past experience with API. Never tried with bean save. Although if it is working with bean save then it should work with API but never worked for me in Sugar9.

  • I just saw a note on another post ( https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/1486/disable-updating-date-modified-when-making-a-rest-api-call/21662#21662 ) that says that in more recent versions setting the flag to false just does not update the value but there is no way of setting it, even using the method I described above would not work past v9 (possibly not even past v8). I suspect time ran faster than I thought... and I must have last used this some years ago...

    My apologies.
    FrancescaS

  • Yes  you are right, I looked to the code of SugarBean.php and there is no possibility to set the timestamp to the given parameter. The flag only says that it should be updated or not, means the old already existing timestamp will not be overwritten. That makes sense if you run some integration jobs which do not really change the data but perhaps add some information flags. With modern integrations the date_modified field is very often used as a timestamp for outstanding data synchronizations, so it makes no sense to allow manipulation by default. If you want to change that date explicitly by API you need an own API endpoint which does not use the SugarBean to update the timestamp but perhaps an SQL query.

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

  • Just out of curiosity, I went into the code and have a look at the SugarBean.php file. So you are right , the above-mentioned code will work and change the date_modified as on line 2101, it is setting the date_modified based on $prev_date_modified variable. As per line 2064, this variable will contain either the old date_modified or the one set by your code.

    Strange that it is not working via API as ultimately APIs are also calling SugarBean saveData function.

Reply
  • Just out of curiosity, I went into the code and have a look at the SugarBean.php file. So you are right , the above-mentioned code will work and change the date_modified as on line 2101, it is setting the date_modified based on $prev_date_modified variable. As per line 2064, this variable will contain either the old date_modified or the one set by your code.

    Strange that it is not working via API as ultimately APIs are also calling SugarBean saveData function.

Children
No Data