model.save() over write the full bean instead of just set fields

Hello Folks,

I have find out a big problem with sugarcrm.

I have created the custom popup for Accounts module by following Adding a new popup view in Sugar 7.x Record View « Sugar Developer Blog – SugarCRM  and it is working fine.

Now Suppose I have Industry field on the model popup. So I have used the code

this.model.set('industry'.'value');
this.model.save();


and industry field is updated with the value that I have been set on the model.
BUT

if you open the model and then open the same record into next tab and change the Name field on the record to suppose 'XYZ' . Now go back to previous tab and apply the changes on the model to set the Industry field.

This should and suppose to just update Industry field but it update the name field with the previous one. It revert the name field as well.

This means this.model.save(); not just update the fields which we set using this.model.set(); it updates all the fields. full bean.

I have tried to save like below

this.model.save({industry:'value'});

but it is having the same effect. it update the full bean.

As of Backbone.js v0.9.9, you can simply pass { patch: true } to save().

I have tried the same but it seems like sugar has not implemented patch.

  • create → POST   /collection
  • read → GET   /collection[/id]
  • update → PUT   /collection/id
  • patch → PATCH   /collection/id
  • delete → DELETE   /collection/id
One record is updated by many users from different departments. And if any changes apply from the model popup and mean while the record has updated by some one then it over rite all the changes of the other users.Can some one give some thoughts on this how to over come from this situation and what is sugarcrm guys answer on this?Patrick McQueen Matt Marum Francesca Shiekh Alan Beam Hiren Darji
  • Sidecar will save entire bean by default and our REST APIs do not support PATCH methods. But Sidecar also supports optimistic record locking.

    bean.save({industry:'value'}, {lastModified: bean.get('date_modified')});

    If the last known modified time for a Sidecar bean is older than the current modified time on the server, then this request will fail with a 409 response and a save will not be processed.

    If you make multiple changes in different tabs on Record views for a single record then Sidecar UI will display a "Merge Conflicts" drawer that will allow an end user to manage the conflicting changes.

    I think the best practice is to try and avoid situations where multiple users are trying to modify same record at same time. This is always a challenging situation to manage from a user experience perspective. If you anticipate conflicts on certain records, then I'd reconsider your data model or I'd recommend allowing only allow the assigned user to change them. This can be configured in Role Management.

    App Ecosystem @ SugarCRM

  • Hello Matt Marum,

    Thank you so much for spending time to answer my question.

    1) We are using model popup ( customized ) to populate data and then apply that changes to model again. So we can not show conflict again on the apply changes from model.

    2) Even sugarcrm conflict gives you 2 options like, keep your changes or keep other changes. But we have situation that requires to merge both changes.

    As per your words :
    I think the best practice is to try and avoid situations where multiple users are trying to modify same record at same time.

    SugarCRM is big platform and design to use for  many users and they should allow to edit the same record . If this is one of the sugarcrm limitation then I was not aware of this. Because we have so many users as well as the portal users , so of course there will be a chance that same record will update by many users at the same time.

    I think you ( SugarCRM Engineer Team) or we ( SugarCRM Developer ) has to find the solution for this kind of situation.
    I am not getting why SugarCRM is not using or thinking to use PATCH method which is supported by backbone as well ?
     Also why sugarcrm does not show the merge request as a third options on conflict ?

    1) Apply your chages
    2) Apply other user changes
    3) Merge your changes with other user changes.

    I have got the work around that I need to retrieve the bean again into model just before going to save the bean.
    But this is not the fair enough solution as I have to retrieve bean 2 times...first time to fetch the information and show on model. Second time before model.save();

    Can you please give some good solution to over come from this kind of situation ?

    As this is very normal usage of sugarcrm as a large extensible system for large no of license users company.

    Thanks
    Prashant

  • Big organizations have lots of people working on lots of different little things. Our largest customers create many records in the CRM. You don't have thousands of people working on one record. What you may find is that you have a parent record with many child records representing subtasks that are assigned out to individuals.

    It is a bad idea to make automatic decisions about how to merge changes. What was the intent of each user? Maybe the two changes from the two different users are fundamentally incompatible.

    For example, one service rep believes that a Case is closed while another service rep is working with this customer and making updates to the Case.

    Who is correct? Which change wins? These people need to talk to one another and get on same page. An automatic decision to merge these changes could be wrong.

    It is much better to have clear roles and responsibilities. One service rep is responsible for updating the Case. They can collaborate with others to make sure that their updates are accurate. It's a business process problem not a technology problem.

    PATCH would be nice to have but not strictly required. You can still make incremental record updates in our REST API using PUT requests. While Sidecar doesn't do this, you only need to include the fields you want to change.

    App Ecosystem @ SugarCRM

  • Hello Matt Marum,

    I might not able to explain you clearly into first post.

    We are having 1 account record. relate to that account we have 1 document.
    now some one open the document record and we have custom action there which open the model popup by retrieving account information and show few fields from account on that model.
    If user submit the model popup data ( only few fields of accounts on model )then only those fields should be updated to account.
     
    Case is , Mean while the user update the document model , we have other system integrated with SugarCRM which has updated 10 different fields that is on the model up on document side. So that changes are save on account.

    Now if user save the model from document side then it has old bean data so all the 10 fields data which has been come from other application will be over rite.

    Now come your point of view. 

    For example, one service rep believes that a Case is closed while another service rep is working with this customer and making updates to the Case.

    Who is correct? Which change wins? These people need to talk to one another and get on same page. An automatic decision to merge these changes could be wrong.

    But suppose one user has change 14 fields and mean while other user has change 5 fields. So sugarCRM interface will show the conflict like

    ACCEPT YOUR CHANGES  ( this will over write 14 fields change by other user )
    ACCEPT OTHER USER CHANGER ( this will over write his 5 fields changes )

    My point is that there should be MERGE option for conflict which is useful to avoid this changes.

    I am not understanding that SugarCRM is based on Backbone JS then why it has not adopted such an important feature like PATCH. We can not over ride all the fields. 

    Is there any method that does UPDATE just fields that we set after retrieve into sidecar architecture ?

    Updating all the fields without any need is not a good solution.

    Thanks
    Prashant

  • In the general case, Sugar cannot make 100% accurate automatic decisions about how to merge conflicting record changes. The damage that could be done to customer data if you get something like that wrong is huge.

    You may be able to for your specific use case, which is great and could be a worthwhile customization for your specific use case.

    Adding PATCH support is not on the radar. You should file an enhancement request to make sure it's tracked.

    App Ecosystem @ SugarCRM

  • Hi Prashant and Matt, 

    I've documented this issue as an enhancement request #80544( https://web.sugarcrm.com/support/issues/80544 ) to be tracked.