Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Creating Requested Item from Business Rule, but Workflow won't link

SSantacroce
Giga Contributor

Hello,

I've been trying to create a BR that creates a new request and linked requested item - I've been doing this with Gliderecord() and Insert(). 

Thing is, the designated workflow won't start nor even link to the RITM. 

I've tried adding: 

var wf = new Workflow();
wf.startFlow('wf_sysId', requested_item, 'insert');
 
but it still does nothing. 
I've also heard about the Cart API, but I haven't found a lot of documentation so I don't know how to use it in this case.
Can anyone help me?
Thanks
3 REPLIES 3

RaghavSh
Mega Patron

@SSantacroce Yes you need to use Cart API, that is the recommended method to submit catalog item through script.

 

Refer : https://www.servicenow.com/community/developer-articles/understanding-sn-sc-cartjs-in-servicenow-its... 

 

You should be able to submit catalog item (generating req and req item) following this article.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

Sarthak Kashyap
Mega Sage

Hi @SSantacroce ,

 

Yes you are correct you can use cart API here, please check below code,

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var cart = new Cart();
    var item = cart.addItem('f44fb27d93c8f2109305f520ed03d66d'); // Your Catalog item Sys ID

    cart.setVariable(item, 'description', 'Test');

    var rc = cart.placeOrder();

    gs.info('Created Request: ' + rc.request_id + ', RITM: ' + rc.items[0]);

})(current, previous);

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

Additionally I tried this on my PDI please check below screenshots

 

BR

SarthakKashyap_0-1762335245294.pngSarthakKashyap_1-1762335262823.png

 

Once I update or create anything on Incident table RITM and Request got created

SarthakKashyap_2-1762335303007.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak