Set Value of a Catalog Variables with other Catalog variables on a SCTASK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi there,
Scripting isn't my strong point, so please be gentle! - I have a catalog variable (script_output) from a catalog item that is being used to create user accounts. I would like to pre-fill the variable script_ouput with other catalog variables from the same catalog item in a template like below when an SCTASK item has been generated:
variables: {
Username: "XXX", (XXX would be populated with catalog variable: user_name)
FirstName: "XXX", (XXX would be populated with catalog variable: first_name)
LastName: "XXX", (XXX would be populated with catalog variable: last_name)
RequestNumber: "XXX" (XXX would be populated with the SCTASK's RITM number )
}
How would I go about creating the script_output to be read only, pre-populate the XXX with the catalog variables as above and have it limited or visible to just the SCTASK? Any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Steps
-> always hide this variable on Catalog Item, RITM and SC Task (Use Catalog UI Policy for this)
-> create after insert BR on sc_task with condition as this
current.request_item.cat_item.name == 'Your Item Name Here'
Script:
Note: Enhance based on how the JSON string you want
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var obj = {
Username: current.variables.user_name.toString(),
FirstName: current.variables.first_name.toString(),
LastName: current.variables.last_name.toString(),
RequestNumber: current.request_item.number.toString()
};
current.variables.script_output = JSON.stringify(obj);
current.update();
})(current, previous);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
