- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 05:12 PM
Hi all,
I created a UI Action that automatically sets an asset state to "Missing," but I'm trying to add a modal that shows a short message and then prompts the user to click on "Cancel" or "Report as Missing." A flow is automatically triggered when an asset state changes to this state, so we're trying to ensure a second validation before the final submission.
Below is my UI Action code:
function reportmissing() {
var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
var miss = new dialogClass('update_asset_missing');
miss.setTitle(getMessage('Confirm'));
gsftSubmit(null, g_form.getFormElement(), 'report_missing');
}
if (typeof window == 'undefined') {
current.install_status = "8";
current.update();
//will be on the current page after UI action
action.setRedirectURL(current);
}
How can I add that to my script?
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 06:55 PM
@taofeek93 Tried and tested solution
Create a UI action as below
UI Action code:
function reportMissing() {
var gm = new GlideModal('report_missing_ui_page');
gm.setTitle('Confirm');
gm.setWidth(400);
gm.render();
}
Create a ui page as below:
UI Page HTML:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<p>Are you sure you want to mark it as report missing?</p>
<br/>
<div style="float: right">
<g:dialog_buttons_ok_cancel ok="return setState()" ok_type="button" ok_text="Report as Missing" ok_style_class="btn btn-primary" cancel="return destroyWindow()" cancel_type="button" cancel_text="cancel" cancel_style_class="btn btn-default" />
</div>
</j:jelly>
UI Page Client Script:
function setState() {
g_form.setValue("install_status", "8");
g_form.save();
destroyWindow();
}
function destroyWindow() {
GlideDialogWindow.get().destroy();
}
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 05:45 PM
Hi @taofeek93
If just a simple comfirm message , you can use javascript's confirm method.
var res = confirm(' do you want to delete?');
if(res == true) {
console.log('OK,delete it')
}else{
console.log('NO~~~')
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 06:55 PM
@taofeek93 Tried and tested solution
Create a UI action as below
UI Action code:
function reportMissing() {
var gm = new GlideModal('report_missing_ui_page');
gm.setTitle('Confirm');
gm.setWidth(400);
gm.render();
}
Create a ui page as below:
UI Page HTML:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<p>Are you sure you want to mark it as report missing?</p>
<br/>
<div style="float: right">
<g:dialog_buttons_ok_cancel ok="return setState()" ok_type="button" ok_text="Report as Missing" ok_style_class="btn btn-primary" cancel="return destroyWindow()" cancel_type="button" cancel_text="cancel" cancel_style_class="btn btn-default" />
</div>
</j:jelly>
UI Page Client Script:
function setState() {
g_form.setValue("install_status", "8");
g_form.save();
destroyWindow();
}
function destroyWindow() {
GlideDialogWindow.get().destroy();
}
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 05:51 AM
@jaheerhattiwaleWhile I am able to preview the modal, the UI Action button itself is not responsive. The UI Action script is not calling my action name "report_missing", could this be the problem? If yes, how do I call the action name in the script you provided below?
function reportMissing() {
var gm = new GlideModal('report_missing_ui_page');
gm.setTitle('Confirm');
gm.setWidth(400);
gm.render();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 05:57 AM
@taofeek93 We don't need action name anywhere. Please post screen shot of UI action with all the fields above the script field.
ServiceNow Community Rising Star, Class of 2023