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

See attached screenshots:
p2.PNGp1.PNG

 

Thank you

@taofeek93 the function in onclick field and the one which is in script are different

jaheerhattiwale_0-1670508431718.png

 

Please make both as reportMissing

 

Please mark as correct answer if this solves your issue.

Worked great - Thank you!

One more thing please; how can I change the UI action button color to Red?

@taofeek93 Mark the "Form style" as destructive.

 

jaheerhattiwale_0-1670512686106.png