Checkbox "Copy billing address to shipping address" not ticked when creating a record through API

This checkbox is always ticked by default when creating a new account record manually in SugarCRM, but never when creating a record through the REST API.

I've searched around and experimented and it seems like it is not even a Sugar field, even though its "field name" appears to be simply "copy".

Sending this in the record creation request does not tick it:

"copy": "true"

Is there a way to tick this checkbox through API only?

Or is the only way really to create an entire customisation with JavaScript code that would tick this checkbox based on a handful of conditions?

  • Hi Artis,

    This checkbox is a User Interface only field. It is checked by default on new records, and it will show as checked, when the field values match. Essentially to have it checked by default when submitting records via the API, you simply need to duplicate the values to both sets of Address fields when submitting the record.

    Another work around, would be to make a custom non-db field, that could be evaluated via a LogicHook to copy the values on submission from the API, or simply override the API endpoint for the module to do the copy when passed a particular value.

    Regards,
    Michael Russell
    Senior Developer Support Engineer

    Learning Resources: http://support.sugarcrm.com | http://university.sugarcrm.com | http://community.sugarcrm.com

  • Thank you for your reply. I've tested whether the checkbox appears ticked when both addresses match. It definitely does not become ticked in that case.

    Is there no way to make it ticked through the API so that when a user unticks it the shipping address is emptied like with the normal behaviour of the checkbox?

  • Hi Artis,

    You are correct, it appears as of latest version it does not show as checked even when the fields match. I had tested that in some previous version before, and that was the case, and it does still appear their is logic to check that the defined fields in the metadata mapping are the same, but its only triggering once, and I believe before the data is loaded. This might be a Bug, so I will run it through our process to see if this is intended functionality now.

    You can review the code for that field in your instance here: clients/base/fields/copy/copy.js

    You might notice a TODO tag, stating the field should be stored in the DB. 

    I tried making a custom field copy_c via studio, and updating the RecordView metadata to use that field instead, however the Field JS Controller doesn't handle getting the value from the model correctly, and there isn't any logic to push the value to the model during DOM Change. Your best bet would be to extend the field, to alter the logic to handle getting the value from the model and setting it when its changed (and using a custom field to store the value, which then allows you to check it from the API). Just know that even with this route, you still need to manually make the values the same via API, unless you also add in a LogicHook on the backend.

    Let me know if you have any questions.

  • Thank you for the detailed answer.

    It seems that it would not be worth it to build a customisation for this checkbox, so I have come to a plan that suits my situation as well.

    That is, fetch the record and check whether or not all different addresses match.

    If they do, assume that both addresses are set to be the same and update both.

    If they do not match, update only the billing address. (In this case, I don't need to update the shipping address)