0
votes

How can I detect when a field value changed by a script, Actually we have a button and update a field value ( i can“t edit this script) in invoices

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @Autor *****
 * @NModuleScope Public
 * @Company ******
 * @NModuleScope Public
 *
*/

define([ 'N/error', 'N/record', 'N/currentRecord', 'N/log', 'N/runtime', 'N/url', 'N/https' ], function( error, record, currentRecord, log, runtime, url, https ) {

    var handler= {};
    handler.fieldChanged = function ( context ) {
        try{
            var currentRecord = context.currentRecord;
            var  field= context.fieldId
            if(campo='custbody_uuid')
            log.error( 'UUID', currentRecord.getValue({ fieldId: 'custbody_uuid' })) ;
                return;

        }catch(e)
        {
            log.error( 'ERROR_fieldChanged', JSON.stringify(e) );

        }
    }

    return handler;
});

How i can detect when a field changed but not by a user?

2
Can please elaborate on your questions. As of my understanding when the field is changed except the user interface. You need to find whether this field is updated via webservice or any other scripts this is correct. - Praveen Kumar

2 Answers

2
votes

N/runtime module is required :

if (runtime.executionContext !== runtime.ContextType.USER_INTERFACE) {
    //your code here
}
0
votes

This is the solution that I am attempting to use on a SalesOrder afterSubmit with SuiteScript 2.0 however it fails with the following errors:

  1. org.mozilla.javascript.EcmaError: TypeError: Cannot read property "USEREVENT" from undefined
  2. org.mozilla.javascript.EcmaError: TypeError: Cannot read property "executionContext" from undefined

Here is the code that fails:

define(["require", "exports", "N/record", "N/log", "N/https", "N/format", "N/runtime","N/ui","N/ui/serverWidget"],
function (require, exports, record, log, https, format, ui, runtime, context) {
if (runtime.executionContext === runtime.ContextType.USEREVENT) {
log.debug("runtime1");
} else {
log.debug("runtime2");
}