How can I set the "Created By" field when importing data through the API?

I'm importing some data through the API, and I found I was not able to set the 'created_by' field when creating records.  I thought I used to be able to do this, but maybe I am mistaken.

POST: <sugar_url>/rest/v11_16/Accounts

{
    "name" : "test5",
    "date_entered":"2024-10-17T12:34:12-04:00",
    "created_by":"seed_will_id"
}

I did notice that in SugarBean, there is a flag you can set (set_created_by), and so I tried that as well, but with the same result

{
    "name" : "test5",
    "date_entered":"2024-10-17T12:34:12-04:00",
    "created_by":"seed_will_id",
    "set_created_by":false
}

I see there is documentation to allow this to be done through the import wizard, but I haven't tested to see if it works. I've too many records to be importing data that way.

https://support.sugarcrm.com/documentation/sugar_versions/14.0/serve/application_guide/import/#Updating_the_Date_Created_and_Created_By_ID_Fields

In the file:

SugarBeanAPiHelper.php:

There is a section that loops through all of the fielddefs and then if there are any matches in the submitted data, it'll add it to the save event.  however, it looks like 'set_created_by' isn't in the field defs, so it never gets passed to the SugarBean save() process.

I can get it to work if I modify the core file like this so sugar thinks that set_created_by is a field.

Is this a bug, or intentional?

Thanks!

Parents
  • As far as I know from old projects the creator can only be set with an additional PUT call having set_created_by set to true.

    The idea behind is that the POST call always sets the created_by to the user running the REST code ( who really created this record ) and if you want to change this user to another id you must run an update on the created_by field with set_created_by explicitely set to true.

    If I‘m wrong correct my guys but don‘t change the code because you need this feature sometimes.

  • This is a sugarcloud instance, so I couldn't change the code even if I wanted to (I don't!).

    I checked out trying to update it afterwards with a 'PUT' method, but the created_by value doesn't even make it to the sugarbean.  It gets removed at some point that I can't determine yet, so that option seems to have been removed.

Reply Children