UI action script to create Req and RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2022 02:23 PM
We have a UI action to create an Incident , but we need similar functionality by up on clicking we need to create a request and associate RITM for that and populate the fields from parent. can some one help me with the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2022 03:55 PM
Hi @NARENDRA KAMMIL ,
Please check below link which is related your problem: -
Solved: Create a request from an "UI action" - ServiceNow Community
I hope this helps
Please mark my answer correct if this helps you
Thanks
Mohit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2022 03:55 PM
When creating a Request, it would be best practice to use the CartJS API (you may find references to the Cart API, which is the older version that still works but it is recommended to use CartJS as it is newer). What you are going to do is create a shopping cart, add an item to it and then checkout. It will mimic the user doing all that themselves and trigger the workflow.
Here is a link to the CartJS API:
Api | CartJS - ServiceNow Developers
The orderNow section gives an easy example to follow that has you load an item into your cart, fill out the variables for it and then checkout. This is the code you are looking for:
var cart = new sn_sc.CartJS();
var request =
{
'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
'sysparm_quantity': '1',
'variables':{
'carrier': 'at_and_t_mobility',
'data_plan': '500MB',
'duration': 'eighteen_months',
'color': 'slate',
'storage': 'sixtyfour'
}
}
var cartDetails = cart.orderNow(request);
gs.info(cartDetails);
You could use a GlideRecord insert to create a record in the Request, RITM and Catalog Task tables but I would not recommend it. For example, the Request Item would not get closed when the last Catalog Task is closed without the workflow in place. I would go the route of using a catalog item as above because that is how the tables are intended to be used.