Brett Zufelt

Avoid unsaved changes prompt in Quotes module

Discussion created by Brett Zufelt on May 11, 2018

I keep getting bit by a bug in Sugar in the Quotes module where it will prompt you of unsaved changes when navigating away from the record even though you just saved it. I'm putting this here to hopefully help anyone else who is experiencing this and can't figure out why.


This can happen if you have any calculated fields in the Quotes, ProductBundles, or Products modules where the fields 'calculated' vardef is set to a string value of '1' or 'true' instead of a boolean value of true. This happens because the Quotes create (modules/Quotes/clients/base/create/create.js) and record (modules/Quotes/clients/base/record/record.js) view controllers along with the Quotes QuotesViewSaveHelper (modules/Quotes/clients/base/plugins/QuotesViewSaveHelper.js) plugin all have code that uses the underscore.js _.chain function to find all the calculated fields with a where condition of .where({calculated: true}). It uses the list of calculated fields to ignore prompting the user for any changes made to calculated fields. The problem is that it will only grab fields that have the 'calculated' property set to the Boolean value of true and not a string representation of true. This has caused me grief because if you save the field in Studio it only sets it to a string value. To get around this you have to edit the calculated field's vardef file and change 'calculated' to a Boolean true. Be aware that the next time you save the field in Studio, it will overwrite your Boolean value with a string again and you will need to change it back to a Boolean in code. I have submitted a bug to Sugar about this behavior (#80746).


Hopefully this is helpful to anyone who has come here desperately seeking answers why it is prompting of unsaved changes in the Quotes module even though you just saved the record.