Controls on Quick Incident UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 03:35 AM
Hi,
Current situation: when we click on 'Quick Incident' button in an Alert form the incident is created from that alert having few mandatory fields empty(in Incident).
To be situation: when we click on 'Quick Incident' button in an Alert form the incident should not be created without those mandatory fields being filled.
In such cases it should redirect user to fill those mandatory fields.
Can anyone suggest how to achieve this?
Thanks in Advance,
Shruti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 04:04 AM
Hi @Shruti08 ,
You can modify the UI Action 'Quick Incident' to validate the mandatory fields before creating the incident.
Add the following code in the 'Script' field:
function onSubmit() {
var mandatoryFields = ['short_description', 'category']; // Replace with your mandatory fields
var emptyFields = [];
// Check if mandatory fields are empty
mandatoryFields.forEach(function(field) {
if (!g_form.getValue(field)) {
emptyFields.push(field);
}
});
// Redirect to fill mandatory fields if any is empty
if (emptyFields.length > 0) {
var redirectUrl = '/incident.do?action=edit&sys_id=-1&';
redirectUrl += emptyFields.map(function(field) {
return 'sysparm_field=' + field;
}).join('&');
gs.addInfoMessage('Please fill in the mandatory fields before creating the incident.');
action.setRedirectURL(redirectUrl);
return false;
}
return true;
}
If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the ✅Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.
Thank you!
Ratnakar