Scripting record producer submissions with catalog api
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2017 10:39 AM
I'd like to add records to the HR Case table in a business rule using a record producer set to an hr_case table.
var cart = new Cart();
var catItemGR = new GlideRecord("sc_cat_item");
catItemGR.addQuery("name", "Contractor Update");
catItemGR.query();
if (catItemGR.next()) {
var item = cart.addItem(catItemGR.sys_id);
cart.setVariable(item, 'opened_by', lv_user_obj.sys_id);
cart.setVariable(item, 'Select_the_contractor_you_wish_to_upd', lv_user_obj.sys_id);
cart.setVariable(item, 'email', lv_current.variables.reqfor_email);
cart.setVariable(item, 'change_end', lv_current.variables.change_end);
cart.setVariable(item, 'contractor_name', lv_user_obj.name);
cart.setVariable(item, 'contractor_email', lv_user_obj.email);
cart.setVariable(item, 'contractor_department', lv_user_obj.department);
cart.setVariable(item, 'contractor_supervisor', lv_user_obj.manager);
cart.setVariable(item, 'contractor_location', lv_user_obj.location);
var rc = cart.placeOrder();
gs.log(rc.number + " should be an HRC number","AMP");
}
Even though the Contractor Update is a record producer for the hr_case table, the above code submits a sc_request record instead.
Does anyone know if placeOrder needs to be specified so that the record is submitted to the correct table?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2018 07:11 PM
Paul, were you ever able to get that code on the link you provided to work?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2018 07:12 PM
Yes, I was able to get this to work.
Very useful bit of code
Recommend using ATF for this functionality.
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 08:56 PM
Seems that within the workflow, there are times with the variables are not filled in, in time.
What is ATF?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 02:11 PM
I faced a similar situation some time ago, in my case i had to put a wait timer of 15 seconds (in the workflow) before the questions answer was populated with variable values from the RP.
in the
ATF is Automated Test Framework i guess...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 04:04 PM
Yeah, ATF lets you raise a new request via a catalogue item using the variables from an existing record.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022