Submit a Record Producer from Run Script action on Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2020 06:02 AM
We have a catalog item (CI) for report requests. A question on this CI asks if the report is to contain HR data. If the answer to the HR question is yes, we have been asked to create a new HR case concurrent with the resulting RITM. In addition, we want the variables on the RITM to be contained on the Variable Editor of the resulting HR Case.
The solution of the top of my head is to set the CI’s workflow to submit a Record Producer (RP) with identical variables and copy the variable values from the CI to the RP, and then submit. The reason for the variables present on the HR Case is for reporting (I would prefer not to create brand new fields on the HR Case table).
I found another post in using a Script Include to create and submit a RP, but am having trouble populating the variables from the CI to the RP. My inability is likely due to my own lack of understanding/experience with scripting.
I have successfully called the Script Include from the Run Script action in the workflow (as evidenced by log entries), but am unsure how to populate the variables on the Record Producer and submit.
Any suggestions?
SCRIPT INCLUDE BELOW:
var Submit_RecordProducer = Class.create();
Submit_RecordProducer.prototype = {
initialize: function(producerSysId) {
this.producerSysId = producerSysId;
this.producer = this.getProducer(producerSysId);
this.targetTable = this.producer.table_name;
this.userVariables = {};
this.rpVariables = this.prepRecordProducerVariables();
},
getProducer: function(producerSysId) {
var gr = new GlideRecord("sc_cat_item_producer");
if (gr.get(producerSysId)) {
gs.info("Yep, we found the RP: " + gr.name);
return gr;
}
return null;
},
setVariable: function(name, value) {
this.userVariables[name] = ‘value’;
},
setVariables: function(variableObject) {
this.userVariables = variableObject;
},
submit: function() {
var targetRecord = new GlideRecord(this.targetTable);
targetRecord.initialize();
targetRecord.applyTemplate(this.producer.template.name);
var v;
// Set mapped fields on target record
for (v in this.rpVariables) {
if (this.rpVariables[v].mapToField == true) {
targetRecord.setValue(this.rpVariables[v].field, this.userVariables[v] || "");
}
}
var targetSysId = targetRecord.insert();
// if there's no target sys_id, don't create any question_answer entries
if (targetSysId) {
// One more loop - insert variables in question_answer table
var qa;
for (v in this.rpVariables) {
qa = new GlideRecord("question_answer");
qa.initialize();
qa.question = this.rpVariables[v].sysId;
qa.order = this.rpVariables[v].order;
qa.table_name = this.targetTable;
qa.table_sys_id = targetSysId;
qa.value = this.userVariables[v];
qa.insert();
}
}
return targetSysId;
},
prepRecordProducerVariables: function() {
var variables = {};
var grItemOption = new GlideRecord("item_option_new");
grItemOption.addQuery("cat_item", this.producerSysId);
grItemOption.query();
while (grItemOption.next()) {
var obj = {};
var name = grItemOption.getValue("name");
obj.field = grItemOption.getValue("field");
obj.mapToField = grItemOption.getValue("map_to_field");
obj.sysId = grItemOption.getValue("sys_id");
obj.order = grItemOption.getValue("order");
variables[name] = obj;
}
return variables;
},
type: 'Submit_RecordProducer'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2020 06:05 AM
Hi,
Please refer to this thread for information: https://community.servicenow.com/community?id=community_question&sys_id=c5440f29dbd8dbc01dcaf3231f96...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2020 06:28 AM
This is the same post I embedded a link to in my initial question. It's not working as I expected and I'm sure it's due to my lack of experience. The Script Include references in that post is getting the proper RP, but I'm not sure how to populate the variables and submit.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2020 06:06 AM
why dont you try with API here "Submit Record Producer (post) "
https://hi.service-now.com/kb_view.do?sysparm_article=KB0686272
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2020 06:32 AM
This does look interesting, but the instructions on the article have me open Developer tools and manually copy/paste the payload into the REST API. I'm not understanding how that will help me achieve the objective.