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

Submit a Catalog Item via Business Rule?

dianemiro
Kilo Sage

Hi Everyone,

I have an existing inbound action with the following code:

var grREQ = new GlideRecord('sc_request');
grREQ.requested_for = '165c7f9adbbfa340a9423ebf9d9619a6';
grREQ.short_description = 'Test_8';
grREQ.description = 'Test_8';
//grREQ.parent = current.sys_id;

var reqSysID = grREQ.insert();

var ritm = new GlideRecord('sc_req_item');
ritm.short_description = 'Test_8';
ritm.description = 'Test_8';
ritm.comments = 'Test_8';
ritm.cat_item = '7f8b78b9db19738002b63ebd7c96198b';
ritm.request = reqSysID;
ritm.state = 1;
//Workflow Trigger
var w = new Workflow();
wfSysId = w.getWorkflowFromName("Infosec Approval");
w.startFlow(wfSysId, ritm, ritm.operation());

ritm.insert();

This is working for inbound action, however, we need to change our process and submit or create this catalog item via business rule and when I used this exact script on BR, it's creating REQ, RITM but the workflow is not attaching. Do you have an idea why this happens? Thank you.

1 ACCEPTED SOLUTION

Use below code with cart API to add comments in RITM.

Make sure to pass your catalog item sys_id in cart

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('f8861cbedbed73008d73771c8c961961');
var rc = cart.placeOrder(); 
var req = new GlideRecord('sc_req_item');
req.addQuery('request',rc.sys_id);
req.query();
while(req.next()){

req.comments = "test comm";
req.update();

}

 

Regards,

Sachin

View solution in original post

11 REPLIES 11

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Diane - As part of Paris release we have added a new action to submit a catalog item from a Flow. Details here

Vaishnavi35
Tera Guru

Hi, 

 

If you can help with Attaching the workflow please?

var w = new Workflow();

wfSysId = w.getWorkflowFromName("Infosec Approval");

w.startFlow(wfSysId, ritm, ritm.operation());

 

I did not understand this?

I have created a question if you can help me? I have a similar requirement of creating an RITM.

I am creating a Demand and RITM when Idea is accepted. I have a BR which is working , Demand is getting created. 

I want one for RITM.

A RITM is getting created but with no variable section and Request.

var grREQ = new GlideRecord('sc_request');
grREQ.initialize();

// Create the RITM
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.initialize();
ritmGr.cat_item = '389e052687e20e909e70c91acebb351f'; // Replace with your catalog item sys_id
ritmGr.variables.u_project_name = current.short_description;
ritmGr.variables.u_project_description = current.description;
ritmGr.variables.u_cost_center_c = current.u_cost_center; // Update this field if necessary
ritmGr.variables.u_portfolio_c = current.portfolio;
ritmGr.variables.u_program_c = current.u_program;
ritmGr.variables.u_requested_for= current.u_requested_for;
ritmGr.variables.u_manager = current.u_requested_for.manager;
ritmGr.variables.u_request_made_by = current.submitter;

// Include Demand Number on RITM
var demandTable = "dmn_demand";
if(GlidePluginManager.isActive('com.snc.project_management_v3')){
	demandTable = SNC.PPMConfig.getDemandTable(current.getTableName());
}

var demand = new GlideRecord(demandTable);
ritmGr.variables.u_demand_number = current.demand.number;

var ritmId = ritmGr.insert();

 

https://www.servicenow.com/community/spm-forum/create-an-ritm-when-idea-is-accepted-catalog-item-is-...

 

Thanks,

Vaishnavi