SDF Installation SuiteScript File Example

The following code sample is the SuiteCloud Development Framework (SDF) installation script that is saved in the File Cabinet folder and named migrate.js. When the migrate.js SuiteScript file is triggered by deployment of SuiteApp v4.1 to an account with SuiteApp v4.0, it creates a “My New Field” transaction body field on the custom transaction record named “My Vendor Payment” and sets a default value for instances in the account.

These are the tasks that occur when migrate.js is executed:

          /**
 * @NApiVersion 2.x
 * @NScriptType SDFInstallationScript
 */
define(['N/record', 'N/search', 'N/runtime'], function(record, search, runtime) {
    function migrate(context) {   
        if (context.fromVersion === '4.0.0' && context.toVersion === '4.1.0') {
           var tSearch = search.create({
              type: search.Type.TRANSACTION,
              columns: [{
                 name: 'internalid'
              }],
              filters: [{
                 name: 'recordtype',
                 operator: search.Operator.IS,
                 values: ['customtransaction_install_script']
              }]
           });
           tSearch.run().each(function(result) {
              var tranInternalId = result.getValue({name: 'internalid'});
              var tran = record.load({
                 type: 'customtransaction_install_script',
                 id: tranInternalId
              });
              var fieldValue = runtime.getCurrentScript().getParameter({name: 'custscript1'});
              tran.setValue({
                 fieldId: 'custbody_install_script',
                 value: fieldValue
              });
              tran.save();
           })
        }
    }
    return {
       run: function run(context) {
          migrate(context);
        }
    };
}); 

        

Related Topics

SDF Installation Script Example of Customizing a SuiteApp Update
SDF Custom Objects in SuiteApps Example
Deploy File that Executes the SDF Installation Script Example

General Notices