- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 06:14 AM
Hi All,
I am trying to create a UI action which should create an Incident from RITM form and I need help with showing up a confirmation box which asks for confirmation before proceeding with Yes/No.
If yes, it has to create Incident and If "no" it should stay on the same form/page
I know the below script I drafted below needs a lot of change. Please suggest the some solution for the same.
var ritmTable = current.getTableName();
var ritmSysID = current.getUniqueValue();
var ritmNum = current.getValue('number');
/* Construct comments and work notes
-----------------------------------------------------------------------------------------------------------------------*/
var comments = 'Incident created from ' + ritmNum;
function openinc() {
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse == 'false') {
return false; //Abort submission
} else
gsftSubmit(null, g_form.getFormElement(), 'transfer_incident');
}
if (typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode() {
var inc = new GlideRecord("incident");
inc.caller_id = current.request.requested_for;
//inc.assignment_group = assignmentGroup;
inc.short_description = current.short_description;
inc.cmdb_ci = current.cmdb_ci;
inc.assignment_group = current.assignment_group;
inc.business_service = current.business_service;
inc.impact = current.impact;
inc.urgency = current.urgency;
inc.description = current.variables.description;
inc.comments = comments;
inc.parent = ritmSysID;
var incSysID = inc.insert();
var incTable = inc.getTableName();
var incNum = inc.getValue('number');
GlideSysAttachment.copy(ritmTable, ritmSysID, incTable, incSysID);
current.comments = 'RITM converted to ' + incNum + '. Please use this reference from now on.';
current.setValue('state', '10');
var mySysID = current.update();
gs.addInfoMessage(gs.getMessage("Incident {0} created", incNum));
action.setRedirectURL(inc);
}
TIA
@Ankur Bawiskar @Anand Kumar P @Runjay Patel @Ravi Gaurav
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 06:35 AM
Hi @DB1 ,
Use client script code like below.
function createIncident() {
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse)
gsftSubmit(null, g_form.getFormElement(), 'create_incident');
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 08:55 PM
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers and also since it's also a correct answer and another way to handle the script.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 06:29 AM
Hi @DB1 ,
You below code in UI action. I have tested it working fine. You can change your field mapping.
function createIncident() {
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse == 'false') {
return false; //Abort submission
} else
gsftSubmit(null, g_form.getFormElement(), 'create_incident');
}
if (typeof window == 'undefined')
runServerSideCode();
//Server-side function
function runServerSideCode() {
var ritmTable = current.getTableName();
var ritmSysID = current.getUniqueValue();
var ritmNum = current.getValue('number');
var comments = 'Incident created from ' + ritmNum;
var inc = new GlideRecord("incident");
inc.caller_id = current.request.requested_for;
//inc.assignment_group = assignmentGroup;
inc.short_description = current.short_description;
inc.cmdb_ci = current.cmdb_ci;
inc.assignment_group = current.assignment_group;
inc.business_service = current.business_service;
inc.impact = current.impact;
inc.urgency = current.urgency;
inc.description = current.variables.description;
inc.comments = comments;
inc.parent = ritmSysID;
var incSysID = inc.insert();
var incTable = inc.getTableName();
var incNum = inc.getValue('number');
GlideSysAttachment.copy(ritmTable, ritmSysID, incTable, incSysID);
current.comments = 'RITM converted to ' + incNum + '. Please use this reference from now on.';
current.setValue('state', '10');
var mySysID = current.update();
gs.addInfoMessage(gs.getMessage("Incident {0} created", incNum));
action.setRedirectURL(inc);
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 02:11 AM
Hi @DB1
You can try the below .. I tested and its working
function createIncident() {
var userConfirmed = confirm('Are you sure you would like to proceed?');
if (userConfirmed) {
try {
gsftSubmit(null, g_form.getFormElement(), 'create_incident');
} catch (e) {
gs.error('Error while submitting the form: ' + e.message);
}
} else {
gs.info('Incident creation was canceled by the user.');
}
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/