- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:47 AM - edited 08-31-2023 05:49 AM
I am trying to create a UI Action for an incident to be created when a contract substate is aborted.
I am very new to script and UI action is not covered in the SNAF course. It will be much appreciated if anyone could help out.
I have tried to create a UI Action below but it does not work.
Show insert YES
Show update YES
Application GLOBAL
Form context menu YES
Condition: (substate=='Aborted') && gs.hasRole("contract_manager")
Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 12:03 AM
Hi Dlam, you need to include current. before substate.
Also, make sure you're checking for the value of the substate, not the label. The value is probably 'aborted' in lower case (I don't have 'Aborted' as an option in my list, so I assume it's either part of something I don't have installed, or a customisation, either way, I can't check it to be sure.)
That would mean your condition should be:
current.substate == 'aborted' && gs.hasRole("contract_manager")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:57 AM
if (current.substate == 'Aborted' && gs.hasRole('contract_manager')) {
createIncident();
}
function createIncident() {
var newIncident = new GlideRecord('incident');
newIncident.initialize();
newIncident.short_description = 'New incident recorded at ' + gs.nowDateTime();
newIncident.caller_id = 'Abby.Lincoln'; // Use the appropriate sys_id or name of the caller
var sysId = newIncident.insert();
// Redirect the user to the newly created incident
action.setRedirectURL('incident.do?sys_id=' + sysId);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:16 PM
Thank you Harish.
Unfortunately after I updated the scripts as yours and tested to submit another catalog item request, still no incident was created. I wonder if it is related the contracts are in a different catalog (Contract Catalog) other than our IT Service Catalog. Any suggestions please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:03 AM
your script looks good.
what's the issue?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:17 PM
Thanks Ankur.
The issue is that when a contract is aborted no incident was created as expected.
I wonder if it is related the contracts are in a different catalog (Contract Catalog) other than our IT Service Catalog. Any suggestions please?