Comparison between forceSyncSourcing, ignoreFieldChange and fireSlavingSync

In NetSuite Client Scripts, the parameters forceSyncSourcing, ignoreFieldChange, and fireSlavingSync are used to control field behavior during script execution. Here’s a detailed explanation of each, along with an example:

1. forceSyncSourcing

  • Description: This parameter forces NetSuite to source fields synchronously. When set to true, it ensures that any sourcing or field change events that would normally be deferred are instead processed immediately. This is particularly useful when the script needs to ensure that all field values are up-to-date before proceeding.

2. ignoreFieldChange

  • Description: When set to true, this parameter prevents any field change events from being triggered. This can be useful to avoid triggering additional scripts or workflows that may be associated with field changes, thereby improving script performance and avoiding unwanted side effects.

3. fireSlavingSync

  • Description: This parameter ensures that dependent fields (slave fields) are updated synchronously. When set to true, it guarantees that any changes to a field that affect other fields are processed immediately.

Example

Here’s an example of a client script that demonstrates the use of these parameters.

javascriptCopy code/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript */define(['N/currentRecord'], function(currentRecord) {
    function pageInit(scriptContext) {
        var rec = scriptContext.currentRecord;

        // Example: forceSyncSourcing        rec.setValue({
            fieldId: 'custfield',
            value: 'exampleValue',
            forceSyncSourcing: true        });
        // Example: ignoreFieldChange        rec.setValue({
            fieldId: 'otherfield',
            value: 'anotherValue',
            ignoreFieldChange: true        });
        // Example: fireSlavingSync        rec.setValue({
            fieldId: 'somefield',
            value: 'value',
            fireSlavingSync: true
        });
    }

    return {
        pageInit: pageInit
    };
});
 

Explanation of the Example

  1. forceSyncSourcing:
  • When setting the value of custfield to 'exampleValue', the forceSyncSourcing parameter ensures that any sourcing that needs to be done as a result of this change is completed immediately.
  1. ignoreFieldChange:
  • When setting the value of otherfield to 'anotherValue', the ignoreFieldChange parameter ensures that no field change events are triggered. This prevents any associated scripts or workflows from running.
  1. fireSlavingSync:
  • When setting the value of somefield to 'value', the fireSlavingSync parameter ensures that any dependent fields that need to be updated as a result of this change are processed immediately.

Use Cases

  • forceSyncSourcing: Useful when subsequent code relies on the sourced values being current and accurate.
  • ignoreFieldChange: Beneficial when making bulk updates or when certain field change triggers need to be bypassed for performance or logic reasons.
  • fireSlavingSync: Necessary when changes to a field must immediately reflect on dependent fields to maintain data integrity or logic flow.

These parameters give developers fine-grained control over how field changes are processed in NetSuite, allowing for more efficient and predictable client-side scripting.

Leave a comment

Your email address will not be published. Required fields are marked *