Trying to Submit another catalog item from current catalog

Ram050670
Tera Guru

Hello All, need some help.

i am trying to submit another catalog item via current catalog form and i have all the variables mapped to the new form and after submiting current request its generating the new item with all the details except the RITM request.requested_for is not generating as per the variable requested_for.

Just need the Requested for Variable and RITM requested for should be same

 

var requestedFor = current.variables.requested_for;
var phonetype = current.variables.phone_system;

var dateneededby = current.variables.expected_start_date;

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('sys id of item', 1);
//fill in the variables on the request item form
cart.setVariable(item, "requested_for", requestedFor);
cart.setVariable(item, "need_by_date", dateneededby);

cart.setVariable(item, "type_of_phone_system", phonetype);


var rc = cart.placeOrder();

 

i am not sure if this is right.

i am doing this in workflow runscript as soon as the request is submited to generate new item request.

 

 

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

Hi @Ram050670  - Try with below scripts.

 



var requestedFor = current.variables.requested_for;
var phonetype = current.variables.phone_system;
var dateneededby = current.variables.expected_start_date;
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('sys id of item', 1);
//fill in the variables on the request item form
cart.setVariable(item, "requested_for", requestedFor);
cart.setVariable(item, "need_by_date", dateneededby);
cart.setVariable(item, "type_of_phone_system", phonetype);
var rc = cart.placeOrder();

var reqRecord = new GlideRecord('sc_request');
reqRecord.get(rc.sys_id);
reqRecord.requested_for = requestedFor;
reqRecord.update();

View solution in original post

10 REPLIES 10

Harsh Vardhan
Giga Patron

Hi @Ram050670  - Try with below scripts.

 



var requestedFor = current.variables.requested_for;
var phonetype = current.variables.phone_system;
var dateneededby = current.variables.expected_start_date;
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('sys id of item', 1);
//fill in the variables on the request item form
cart.setVariable(item, "requested_for", requestedFor);
cart.setVariable(item, "need_by_date", dateneededby);
cart.setVariable(item, "type_of_phone_system", phonetype);
var rc = cart.placeOrder();

var reqRecord = new GlideRecord('sc_request');
reqRecord.get(rc.sys_id);
reqRecord.requested_for = requestedFor;
reqRecord.update();

Hi  Harshvardhan,

is it possible to get the requested_for to get at the placing order? instead of updating the record. 

because the new item has manager approval based on the requested for as soon as it generates the item.

Have you tried using sn_sc.CartJS() method ?

 

Doc reference:

https://docs.servicenow.com/en-US/bundle/rome-application-development/page/app-store/dev_portal/API_... 

 

 

 

 

 

Yes i did that. but getting an error invalid Requested for and both req fields are empty.