Quote Line Items not loading properly

Hi all,

When I'm trying to reload the Quote Line Item (QLI) after a change in the parent record (Quote), the QLI is not loading with the recent value. I need to imply a 3Sec delay for it to load the actual updated value. Following is the scenario:

Quote has a field "Stage" it is a status field which can be changed, on back of any change some "Hooks" will be executed, This HOOKS update some field in QLI in the Product Module. So we need to show the user the updated QLI in Quote after the "Status" field change. 

But unfortunately, After quote moved to sidecar the "QLI is considered as a different component than the Quote" i.e. Quote is a different component and QLI is a different component. (As far as I understood). So the QLI will not be loaded automatically, So we made a change to the "handleSave" of Quote to Reload the QLI.

src/custom/modules/Quotes/clients/base/views/record/record.js

handleSave: function () {

      this._super('handleSave');

      

      // NOTE: The following will run after the record is saved
      // Fetch the current QLI after the state transition change

       // Removing existing QLI from the view and reload else we will end up in duplicating the QLI view

      $('.quote-data-group').remove();


      if (!this.disposed) {
            SUGAR.App.controller.context.reloadData({});
      }
},

So the Above does the Reload of QLI but this is not working all the time may be the HOOKS in the backend take long to update so we don't get the recent vale/changes int he QLI. So in order to overcome the issue, we added a 3 sec wait time.

handleSave: function () {

      this._super('handleSave');

      

      // NOTE: The following will run after the record is saved
      // Fetch the current QLI after the state transition change

       // Removing existing QLI from the view and reload else we will end up in duplicating the QLI view

      $('.quote-data-group').remove();


      if (!this.disposed) {

            // Set the delay to reload the QLI because we trigger hook to update Line Items
            // because of the background process we deliberately delay the load.
            setTimeout(function () {
                  SUGAR.App.controller.context.reloadData({});
             }, 3000); // 3 seconds delay
      }
},

The above code works but not sure about the correct approach to the issue. Any help?

Parents Reply Children