- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 09:19 PM
I have created a catalog item that I want to automate the trigger of that catalog item every 3 months. I used scheduled entity generation to automate this and wrote a script to create an REQ and RITM for the same. But the values in REQ like requested for, short description and description are not populating when I execute it using the execute now button present at the bottom left corner. I have the same fields (requested for, short description and description) present on the catalog item as well. I tried to Glide Record as well but values on REQ number generated does not populate. Find the screenshot below for the code.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 09:52 PM
use this
orderNow function returns JSON object so updated the code to send the REQ sysId so that updateRITM function can query it correctly
// var answer = false;
// var date = new GlideDateTime();
// var month = date.getMonth();
// var day = date.getDayOfMonth();
// if (month == 1 || month == 4 || month == 7 || month == 10)
// Create a new catalog request
createRequest();
function createRequest() {
var cart = new sn_sc.CartJS();
var request = {
'sysparm_id': '354c9968fbec269033c5ff57aeefdccb', // sys ID of catalog item SAP EFS Approval Hierarchy Review Data Upload
'sysparm_quantity': '1',
'variables': {
'requested_for': '8e4d9138dbe1cb042686da94ce961924', //sys ID of Louise Gulliford
'short_description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
'description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
}
};
var cartDetails = cart.orderNow(request);
updateRITM(cartDetails.request_id);
}
function updateRITM(reqSysId) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', reqSysId);
ritm.query();
if (ritm.next()) {
ritm.requested_for = '8e4d9138dbe1cb042686da94ce961924';
ritm.short_description = "Create SAP EFS Approval Hierarchy Review Data Upload ";
ritm.update();
// update Requested for on REQ as well
var req = ritm.request.getRefRecord();
req.requested_for = '8e4d9138dbe1cb042686da94ce961924';
req.update();
}
}
{
answer = true;
}
answer;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 09:41 PM
share the script here and not the screenshots.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 09:45 PM
@Ankur Bawiskar
Sharing the script here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 09:52 PM
use this
orderNow function returns JSON object so updated the code to send the REQ sysId so that updateRITM function can query it correctly
// var answer = false;
// var date = new GlideDateTime();
// var month = date.getMonth();
// var day = date.getDayOfMonth();
// if (month == 1 || month == 4 || month == 7 || month == 10)
// Create a new catalog request
createRequest();
function createRequest() {
var cart = new sn_sc.CartJS();
var request = {
'sysparm_id': '354c9968fbec269033c5ff57aeefdccb', // sys ID of catalog item SAP EFS Approval Hierarchy Review Data Upload
'sysparm_quantity': '1',
'variables': {
'requested_for': '8e4d9138dbe1cb042686da94ce961924', //sys ID of Louise Gulliford
'short_description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
'description': 'Create SAP EFS Approval Hierarchy Review Data Upload',
}
};
var cartDetails = cart.orderNow(request);
updateRITM(cartDetails.request_id);
}
function updateRITM(reqSysId) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', reqSysId);
ritm.query();
if (ritm.next()) {
ritm.requested_for = '8e4d9138dbe1cb042686da94ce961924';
ritm.short_description = "Create SAP EFS Approval Hierarchy Review Data Upload ";
ritm.update();
// update Requested for on REQ as well
var req = ritm.request.getRefRecord();
req.requested_for = '8e4d9138dbe1cb042686da94ce961924';
req.update();
}
}
{
answer = true;
}
answer;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 09:57 PM
Hi @nupur_goswami ,
you should be able achieve this with flow designer
and it's very easy to implement as well check
my last comment in the below post
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya