Creating a new SugarBean with a pre-created UUID

I have a custom API endpoint that we use to send a large number of records at a time. The endpoint works for updating records and inserting new records without a pre-created UUID, but when we send records with a pre-created UUID, we get the UUID back as a response, but the record is not written into the database.

To answer the questions this is going to cause, we do not use the bulk API endpoint due to a performance issue, since it is a http request to make multiple http requests. Also, we are a SugarCloud client so there is a 20 requests a minute limit, which is easy to violate. 

Does anyone have any insight as to why SugarBean might have an issue with new records with pre-created UUIDs?

Here is the code for the custom endpoint.

    public function setEntriesMethod($api, $args)
    {
        if (empty($args)) {
            return false;
        }
        $results = array();
        foreach ($args as $module => $records) {
            if (is_array($records)) {
                foreach ($records as $fieldsArray) {
                    $sugarBean = $this->_processEntry($module, $fieldsArray);
                    $results[$module][] = $sugarBean->id;
                }
            }
        }
        return $results;
    }

    private function _processEntry($module, $fieldsArray)
    {
        $Logger = Factory::getLogger('default');
        if (array_key_exists('id', $fieldsArray)) {
            $sugarBean = BeanFactory::retrieveBean($module, $fieldsArray['id']);
            if (is_null($sugarBean)) {
                $Logger->debug('Record ' . $fieldsArray['id'] . ' does not exist');
                $sugarBean = BeanFactory::newBean($module);
            }else{
                $Logger->debug('Record ' . $fieldsArray['id'] . ' does exist');
            }
        } else {
            $sugarBean = BeanFactory::newBean($module);
        }
        if (is_null($sugarBean)) {
            return null;
        }
        foreach ($fieldsArray as $field => $data) {
            $sugarBean->$field = $data;
        }
        $sugarBean->save();
        return $sugarBean;
    }

Parents
  • Could you update your code to use the REST API instead of the 10+ year deprecated SOAP API?

    There is built-in functionality in Sugar 11/12. There is an additional field sync_key and matching REST API functions which allow for the use of an external ID.

    If you need to continue using the SOAP API. The SugarBean has a parameter new_with_id when your record is created on line 25 assign the ID and set new_with_id = true;

    /**
    * When createing a bean, you can specify a value in the id column as
    * long as that value is unique. During save, if the system finds an
    * id, it assumes it is an update. Setting new_with_id to true will
    * make sure the system performs an insert instead of an update.
    *
    * @var BOOL -- default false
    */
    var $new_with_id = false;
Reply Children
No Data