How to pop up a confirmation message on UI Action Button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2024 12:48 AM
Hi Experts,
Good Day!
I have one requirement whenever user tries to click on "Create report request" button it is automatically creating a another request on another table. Here my requirement is once user clicks on button on form it should populate a alert popup like confirmation message "Are you want to sure create a request ?" 'YES' or 'No'
If user clicks on yes it should move forward if it no form should same as it is. Below is the UI Action script and screenshots
Anyone could you please help me on this
Any help will be appreciated Thanks in Advance
AAKHIL
UI Action Script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2024 01:20 AM
Hello @Aakhiil ,
To display the pop up you can use confirm() method.
The syntax to use this method is:
var conf = confirm("Please enter the text which you want use in here for confirmation");
// confirm return true if ok is pressed and false if cancel is pressed
if(conf== true){
//do something
}
else{
return false; // do something else
}
*************************************************************************************************************
"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2024 01:36 AM
Hi @Aakhiil ,
You have to make UI action client callable, use below code it will work.
function confirmMe(){
var conf = confirm("Are you want to sure create a request ?" 'YES' or 'No'");
if(conf== true){
gsftSubmit(null, g_form.getFormElement(), 'sysverb_insert'); // replace 'sysverb_insert' with your ui action name
}
}
// Check if a record already exists
var existingRequest = new GlideRecord("u_monument_requests");
existingRequest.addQuery("u_monument_requests_requester", current.u_vms_requester);
existingRequest.addQuery("u_monument_request_summary", current.u_vms_summary_of_request);
existingRequest.addQuery("u_monument_request_client", current.u_vms_client);
existingRequest.addQuery("u_monument_request_vms", current.u_vms_vms);
existingRequest.query();
if (existingRequest.next()) {
var existingMonumentNumber = existingRequest.getValue("number");
gs.addErrorMessage("Record already created refer to Monument Number: " + existingMonumentNumber);
action.setRedirectURL(current); // Redirect back to the current record
} else {
// Create a new record
var mrequest = new GlideRecord("u_monument_requests");
mrequest.u_monument_requests_requester = current.u_vms_requester;
mrequest.u_monument_request_summary = current.u_vms_summary_of_request;
mrequest.u_monument_request_client = current.u_vms_client;
mrequest.u_monument_request_vms = current.u_vms_vms;
//mrequest.u_monument_report_assigned = current.u_vms_assigned_to;
mrequest.u_monument_request_criticality = current.u_vms_criticality;
mrequest.u_business_purpose = current.business_impact;
mrequest.state.setValue(-4);
var sysID = mrequest.insert();
current.mrequest_id = sysID;
var mySysID = current.update();
gs.addInfoMessage("mrequest " + mrequest.number + " created");
mrequest.work_notes = "Created by record number: " + current.number;
mrequest.update();
current.work_notes = "This request was cancelled and converted to a Monument Reporting Support Request: " + mrequest.number;
current.u_vms_status = 11; //Set the VMS Record to Cancelled
current.update();
// Redirect to the created record
action.setRedirectURL(mrequest);
action.setReturnURL(current);
}
-------------------------------------------------------------------------
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
-------------------------------------------------------------------------