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

Its a URL that takes you to the HR Case Templates on your instance.  


Uncle Rob
Kilo Patron

I'm free tomorrow and dedicating all my hours to ServiceNow community.


If you'd like me to walk through this with you live, deconstruct where you're currently at, and put you on the right path forward, please let me know.



RDF


It looks like if we can't use placeOrder(), we'll need to write a script that properly runs the inserts so it adds both the hr_case record as well as the associated variables.



Is there a direct message function in servicenow community?


Hi Johnny,



Did you find a solution for your use case? can you please share.



Regards,


JS


The SN Nerd
Giga Sage
Giga Sage

Perhaps you might want to check out this code, that emulates the submission of a record producer:



https://community.servicenow.com/message/734832#734832



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022