UI action button not working properly.

Pallavi65
Tera Contributor

Hello all,

 

Good evening.

I have created a button on Incident form.

UI action name: Escalate

So, the user should be able to click the button only twice.

SO, I have created a field "Escalation count" (u_escalation_count) of type integer on the Incident form.

So, once the user clicks on the button for the first time, the count has to be updated by 1. 

When the user clicks the button for the second time, then count has to be updated by 2.

For this I have written a code, but the problem is,

The count is getting updated with 1 for the first time, but the second time, the value is updating with 2 but when I refresh the form, the value is again getting back to 1.

 

Please help me.

My Code:

function doEscalate(){
   
    var ec = g_form.getValue('u_escalate_count');
    if(ec==0){      
        g_form.setValue('u_escalate_count',1);  
    }
    else if(ec==1){        
        g_form.setValue('u_escalate_count',2);
            }

    gsftSubmit(null,g_form.getFormElement(),'escalate_now');
}

if(typeof window == 'undefined')
setRedirect();
function setRedirect(){
    //current.u_escalate_count = ec;
    current.update();
    action.setRedirectURL(current);
}
 
 
Regards,
Pallavi
1 ACCEPTED SOLUTION

The following worked for me.

 

 

 

 

function doEscalate(){
    var ec = g_form.getValue('u_escalate_count');
	alert('doEscalate: ec = ' + ec);
    if(ec==0){      
        g_form.setValue('u_escalate_count',1);  
    }
    else if(ec==1){        
        g_form.setValue('u_escalate_count',2);
     }
	alert('doEscalate: submitting record, u_escalation_count = ' + g_form.getValue('u_escalation_count'));
    g_form.submit();
    current.update();
    action.setRedirectURL(current);
}

 

 

That is, if the default value of your custom field is 0. If null, it doesn't work.

 

View solution in original post

6 REPLIES 6

Ramesh Poola
Tera Guru

Hi @Pallavi65,

 

did you tried to understand by putting the logs. I think the setRedirect(); function may be not calling in the other case when ec==1. Please put some logs and check once this setRedirect();  function is calling or not.

and also try to inspect the browser and see if you are getting any errors. if Isolate script check box is checked in the UI action then please uncheck and see once.

 

Best Regards,
Ramesh

Bert_c1
Kilo Patron

@Pallavi65 

 

The line: 

 

    gsftSubmit(null,g_form.getFormElement(),'escalate_now');

 

does nothing that I can see, try:

 

g_form.submit();

 

 

see:

 

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/client/c_GlideFormAPI#r_GlideFo... 

 

Hi Bert,

 

Yup. It's working fine. But it is navigating to Previous page once I click that button.

But it should stay on the same page.

 

 

Regards,

Pallavi

You'll need to provide more context. I get an error with the ui action in my PDI

 

Screenshot 2024-11-12 151101.png

 

As you can see, where is 'escalate_now' defined? Post screenshots as I have done.

 

And you never call the setRedirect() function in your code.

 

An example from searching UI Action records where 'script', contains, detRedirectURL shows:

 

action.setRedirectURL("export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true&sysparm_is_remote=false&sysparm_ck=" + gs.getSessionToken());

from the "Export to XML" UI action.