How to Trigger change workflow/record producer from transform script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2014 11:45 AM
We have a requirement to create a change request with workflow and approval from a transform map script.
to create the change record, we have a record producer in place. But i'm not sure how to trigger the record producer from transform script and how to ploulate theRP variables.
I tried using Catalog API as mention below but it is creating a RITM instead of change request.
var cart = new Cart(); var item = cart.addItem('sys id of record producer'); cart.setVariable(item, 'RP variable name', source.TransformMapVariableName); ..... var rc = cart.placeOrder(); gs.log(rc.number);
above code is not working, is there any other mathod to invoke change_request with workflow from a transform script ?
Pradeep Sharma can you help ?
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2016 10:34 PM
Instead of eval(), try the following:
var scriptEval = new GlideScopedEvaluator();
scriptEval.putVariable('current',current);
scriptEval.putVariable('producer',producer);
scriptEval.evaluateScript(this.producer, 'script', null);
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2018 06:44 PM
Am I missing something here? I have in onBefore script in a transform map and when I call this code (above), I get an error:
org.mozilla.javascript.EcmaError: Cannot set property "u_requested_for" of undefined to "00021a834f8e66c00bc050ee0310c7ea"
Caused by error in sys_script_include.9ec972364f734340b0f4ecee0210c7bb.script at line 32
29: //Function to handle employee termination event from ADP.
30: function onTerminate(rp_sysId, rpTableName){
31: var empGR = getEmpInfo(source.u_idvalue);
==> 32: var termEmp = new RecordProducerUtil(rp_sysId);
33:
34: termEmp.setVariable("u_requested_for", empGR.sys_id.toString());
35: termEmp.setVariable("category", "Termination");
IS this not correct?
function onTerminate(rp_sysId) //rp_sysid is the sys_id of the record producer
{
var empGR = getEmpInfo(source.u_idvalue);
var termEmp = new RecordProducerUtil(rp_sysId);
termEmp.setVariable("u_requested_for", empGR.sys_id.toString());
termEmp.setVariable("category", "Termination");
termEmp.submit();
}
I'm trying to do this so that I do not have to recreate a workflow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2018 12:34 AM
Nice script, thanks for that!
Couple of caveats as I did include this in a scoped application:
- gs.print is not available, rather use gs.info
- applyTemplate seems not to work (need to check for alternative)
- would be awesome if this would also execute the record producer script to make sure we have all static variables / stuff in there as well.
I'll check on the these and maybe post an update if I get to working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2014 07:52 PM
why cant you insert a record directly into the table and set the values to the fields required? the workflow should get attached after the record insertion too.
the above script is some serious writing but if it can be done at table record insertion, why go to the record producer route...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2020 07:48 AM
In my case, i have the record and i am just trying to insert the catalog variables in question_answer table. I was able to insert the variables into question_answer table and the variables appear in my record as well but none of the ui policies/client scripts related to those variable runs.
Did you face these issues and try to resolve it?