how to add a ui action button in pop up message in purchase order form

raj765_32
Tera Contributor

hi can anyone help me with the requirment for 

 

in the purchase order form there is a ui action button called as cancel, i want to display an alert pop up after user clicks on cancel and ui action in the message stating as do you want to cancel it? comform ui action button in message, after user clicks on comform then status should get cancelled.

 

Below is the code 

 

 cancelPO(current);

function cancelPO(grRecord) {

 var gr = new GlideRecord('proc_po_item');
gr.addQuery('purchase_order', grRecord.getUniqueValue());
 gr.query();

 while (gr.next()) {
 gr.status = 'canceled';
 gs.addInfoMessage("Please confirm that you want to cancel this PO request");

gr.update();

 }

1 ACCEPTED SOLUTION

Voona Rohila
Kilo Patron
Kilo Patron

Hi @raj765_32 

You need client UI Action for this:

In UI Action :

Client checkbox should be true

Action name : give any name here,this will be used in gsftsubmit in the script.

onclick:onClick();

code://modify field names accordingly

 

function onClick() {
    var usrResponse = confirm(getMessage("Pease confirm that you want to cancel "));
    if (usrResponse == true)
        gsftSubmit(null, g_form.getFormElement(), 'cancel_case'); //Add the action name here
    else
        return false;
}


if (typeof window == 'undefined')
    cancelCase();

function cancelCase() {
  var gr = new GlideRecord('xyz');
    gr.addQuery('purchase_order', current.sys_id);
    gr.query();
    while (gr.next()) {
        gr.status = 'canceled';
        gr.update();

    }    action.setRedirectURL(current);
}

 

 

 Refer articles below

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0657198

 

https://docs.servicenow.com/en-US/bundle/utah-api-reference/page/script/useful-scripts/reference/usi...

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

1 REPLY 1

Voona Rohila
Kilo Patron
Kilo Patron

Hi @raj765_32 

You need client UI Action for this:

In UI Action :

Client checkbox should be true

Action name : give any name here,this will be used in gsftsubmit in the script.

onclick:onClick();

code://modify field names accordingly

 

function onClick() {
    var usrResponse = confirm(getMessage("Pease confirm that you want to cancel "));
    if (usrResponse == true)
        gsftSubmit(null, g_form.getFormElement(), 'cancel_case'); //Add the action name here
    else
        return false;
}


if (typeof window == 'undefined')
    cancelCase();

function cancelCase() {
  var gr = new GlideRecord('xyz');
    gr.addQuery('purchase_order', current.sys_id);
    gr.query();
    while (gr.next()) {
        gr.status = 'canceled';
        gr.update();

    }    action.setRedirectURL(current);
}

 

 

 Refer articles below

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0657198

 

https://docs.servicenow.com/en-US/bundle/utah-api-reference/page/script/useful-scripts/reference/usi...

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP