- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2023 01:04 PM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2023 01:13 PM
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();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2023 03:29 PM
It should be something like this.
Quick Example:
var requestedFor = current.variables.<variableName>;
var cart = new sn_sc.CartJS();
cart.setRequestedFor(requestedFor); // This will set Request requested for
var item ={
'sysparm_id': '<sysid Of the ITem>',
'sysparm_quantity': '1',
'variables':{
'<VariableName>': requestedFor
}};
var cartVals = cart.addToCart(item);
var checkoutVals = cart.checkoutCart();
Hope it will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2023 03:55 PM
var requestedFor = current.variables.request_for;
var cart = new sn_sc.CartJS();
cart.setRequestedFor(requestedFor); // This will set Request requested for
var item = {
'sysparm_id': 'sysid of item',
'sysparm_quantity': '1',
'variables': {
'requested_for': requestedFor,
'need_by_date': dateneededby,
'type_of_phone_system': phonetype,
}
};
var cartVals = cart.addToCart(item);
var checkoutVals = cart.checkoutCart();
output: empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 12:13 PM
I used this solution and updated the other catalog item workflow approvals with variable.
Thanks again!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2023 10:29 AM
also can you Help me update the Opened by on RITM?
//Update Req for on RITM
var reqRecord = new GlideRecord('sc_request');
reqRecord.get(rc.sys_id);
reqRecord.requested_for = requestedFor;
reqRecord.opened_by = openedby;
reqRecord.update();
i have added Opened by also but its updating REQ but not in RITM. can you help on this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2023 03:41 PM
@Ram050670 Can you try to pass requested for as an argument in Cart() method ?
Eg:
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 , requestedFor); // added here
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();