UI action popup with yes no buttons

shaik23
Tera Expert

Hi everyone,

I’ve created a UI action popup window with Yes and No buttons. The intended behavior is that when a user clicks the UI action button, a confirmation window should appear. If the user clicks ‘Yes,’ the task current task and the task related to the parent table should be canceled. However, currently, the popup window appears but doesn’t perform any action. Below, I’m sharing the script I’ve used. Can you please assist?

UI action :

function showCancelDialog() {
    var dialog = new GlideDialogWindow("cancel_uar_dialog");
    dialog.setTitle('Cancel UAR Confirmation');
    dialog.setPreference('sys_id', g_form.getUniqueValue());
    dialog.render();
}

if (typeof window == 'undefined') {
    showCancelDialog();
}
shaik23_0-1719842394181.png

 

 
 
Ui pages:



HTML code:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div>
  <h2>Are you sure you want to cancel this UAR?</h2>
  <button id="yes_button" class="btn btn-danger" onclick="yes_button();">Yes</button>
  <button id="no_button" class="btn btn-secondary" onclick="no_button();">No</button>
</div>
</j:jelly>

Client side:

function clickedNo() {
    GlideDialogWindow.get().destroy();
   // return false;
}

function clickedYes() {
    var sysId = g_dialog.getPreference('sys_id');
    var gr = new GlideRecord('u_user_access_review');
    if (gr.get(sysId)) {
        gr.setValue('state', '7'); // Make sure 'closed_skipped' matches your state value
        gr.update();

        var taskGR = new GlideRecord('u_uar_task');
        taskGR.addQuery('parent', sysId);
        taskGR.addQuery('active', true);
        taskGR.query();
        while (taskGR.next()) {
            taskGR.setValue('state', '4'); // Cancelled
            taskGR.update();
        }

        g_form.refresh();
    }
    GlideDialogWindow.get().destroy();
}
 
shaik23_1-1719842434632.png

 

1 ACCEPTED SOLUTION

HI @Bhavya11 
Thanks for your suggestion i made some changes working fine

View solution in original post

3 REPLIES 3

Bhavya11
Kilo Patron

Hi @shaik23 

 

you have used GlideRecord in client script it does not work so try below code

Please made the changes in your UI page script it will work fine.

 

in HTML of UI page make these changes 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_sys_id" value="${RP.getWindowProperties().get('sys_id')}"/>   
<input id="record_sys_id" type="hidden" value="${jvar_sys_id}" />
<div>
  <h2>Are you sure you want to cancel this UAR?</h2>
  <button id="yes_button" class="btn btn-danger" onclick="yes_button();">Yes</button>
  <button id="no_button" class="btn btn-secondary" onclick="no_button();">No</button>
</div>
</j:jelly>

in Client Script 

 

function no_button() {
    GlideDialogWindow.get().destroy(); // Destroy dialog window on 'no' button click
}

function yes_button() {
    var sys_id = $j('#record_sys_id').val();
    var grajax = new GlideAjax('UARMUpdates');
    grajax.addParam('sysparm_name', 'UARUpdate');
    grajax.addParam('sysparm_Id', sys_id);
    grajax.getXMLAnswer(fetchvalue);

    function fetchvalue(response) {
        if (response) {
            alert("cancelled all the UAR  and its task");
        }


    }

}

 Create client callable script include and and try these code

UARUpdate: function() {
		var sysId=this.getParameter('sysparm_Id');
        var gr = new GlideRecord('u_user_access_review');
        if (gr.get(sysId)) {
            gr.setValue('state', '8');  // Make sure 'closed_skipped' matches your state value
            gr.update();
            var taskGR = new GlideRecord('u_uar_task');
            taskGR.addQuery('parent', sysId);
            taskGR.addQuery('active', true);
            taskGR.query();
            while (taskGR.next()) {
                taskGR.setValue('state', '4'); // Update task state to 'Cancelled'
                taskGR.update();
            }
            return true; // Success
        } else {
            return false; // Error
        }
    },

 

Please mark my answer correct if it helps you

 

Thanks

BK

HI @Bhavya11 
Thanks for your suggestion i made some changes working fine

Bhavya11
Kilo Patron

Hi @shaik23 

 

Please Accepted Solution.

 

Thanks,

BK

 

 

Thanks

BK