Catalog item that does not raise a request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 06:42 AM
Hi folks,
We have a requirement to create a form that when submitted, kicks of a script to raise either an INC, REQ or CHG based upon the user input. We created a catalog item and associated workflow but when the cat item form is submitted, a REQ is always raised by default.
What is the best way to accomplish this objective? A record producer will always want to create a record so that will not work. Is there a way to prevent the REQ being raised and just run the workflow?
Is there another method in ServiceNow that will allow us to create a form that just kicks off the workflow?
Thanks,
Ken
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 06:54 AM
Hi @Ken Berger
In the workflow associated with the catalog item, you can use a script (e.g., a script task) to check the user’s input and conditionally create the desired record (INC, REQ, or CHG).
You can consider following script for reference:
// Assuming 'inputType' is the variable capturing user choice
if (current.variables.inputType == 'Incident') {
var incident = new GlideRecord('incident');
incident.initialize();
// Set fields from variables
incident.short_description = current.variables.short_description;
incident.insert();
} else if (current.variables.inputType == 'Change') {
var change = new GlideRecord('change_request');
change.initialize();
// Set fields from variables
change.short_description = current.variables.short_description;
change.insert();
}
Another approach is you can also create a UI action on the catalog item to process the input and create records. Create a UI action that, when clicked, checks user input and creates the appropriate record (INC, REQ, or CHG) without raising a REQ by default.
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 07:39 AM
Hi Rajesh,
Thanks for your reply. We have a script activity in the workflow to raise the needed item (INC, REQ or CHG) and this is executing and working properly. The problem is that the default action of the cat item is to make a REQ, which is also being created. We need to stop this part.
The UI action required further user input which may not be an option.
-Ken
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 09:05 AM
I was able to stop the REQ creation by a before insert BR:
(function executeRule(current, previous /*null when async*/) {
// Query the associated request items for the current request
var reqItemGr = new GlideRecord('sc_req_item');
reqItemGr.addQuery('request', current.sys_id); // Link to the current request
reqItemGr.query();
// Loop through the associated request items
while (reqItemGr.next()) {
// Check if the catalog item matches the specified catalog item's sys_id
if (reqItemGr.cat_item == '<sysId of CAT ITEM>') {
gs.addInfoMessage('Request creation for this catalog item has been stopped.');
current.setAbortAction(true); // Prevent the creation of the request
return; // Exit the script early
}
}
})(current, previous);
But it is still saying the REQ was created. I need to suppress the bogus pop-up that appears saying that the REQ was created.