The CreatorCon Call for Content is officially open! Get started here.

Scripting record producer submissions with catalog api

johnny27
Tera Contributor

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?

15 REPLIES 15

Paul, were you ever able to get that code on the link you provided to work?  


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

Seems that within the workflow, there are times with the variables are not filled in, in time.  



What is ATF?


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...


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