Jonathan Evans
Jonathan Evans

Reputation: 3

Suitescript 2.0 - How to get custom workflow fields into script

I've created a workflow that has a workflow action script to create a new record using mass update.

This is working but now I need to pass values from custom workflow fields set in the mass update screen into the script so I use them to set values on the new record and I just can't figure it out.

Any help would be greatly appreciated.

Thanks

Upvotes: 0

Views: 1701

Answers (2)

bknights
bknights

Reputation: 15367

If you have created a custom mass update script you would have created parameters accessed like :

runtime.getCurrentScript().getParameter({name:'custscript....'});

If so and you are then triggering the work flow via:

workflow.initiate({
    recordType:'customer', ...

then you might do something like:

/**
 * @NApiVersion 2.x
 * @NScriptType MassUpdateScript
 */
define(["N/runtime", "N/workflow"], function (runtime, workflow) {
    function each(params) {
        workflow.initiate({
            workflowId:'customworkflow_target_id'
            recordType: params.type,
            recordId: params.id
            defaultValues:{
                custworkflow_field_1:runtime.getCurrentScript().getParameter({name:'custscript_field_1'})
                // and so on. of course you'll probably dereference runtime.getCurrentScript() if you have multiple parameters
                // You'll have to define workflow fields for every value you want to pass. 
                // custscript_field_1 is from the id of the workflow fields. 
                // For sanity's sake I recommend giving your script parameters similar ids as the workflow field ids
            }
        });
    }
    exports.each = each;
});

Upvotes: 1

Rusty Shackles
Rusty Shackles

Reputation: 2840

Create parameters in your script then when you are calling the custom action script in the workflow, pass the workflow field values to the script parameters.

Upvotes: 0

Related Questions