Add a confirm action modal to UI Action

taofeek93
Tera Contributor

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

 

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage

@taofeek93 Tried and tested solution

Create a UI action as below

jaheerhattiwale_0-1670468004587.png

 

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:

jaheerhattiwale_1-1670468049431.png

 

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.

View solution in original post

8 REPLIES 8

newhand
Mega Sage

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~~~')
}

 

jaheerhattiwale
Mega Sage

@taofeek93 Tried and tested solution

Create a UI action as below

jaheerhattiwale_0-1670468004587.png

 

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:

jaheerhattiwale_1-1670468049431.png

 

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.

@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();
}

 

 

@taofeek93 We don't need action name anywhere. Please post screen shot of UI action with all the fields above the script field.