We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

UI action is not working(the field value is not updated even when the button is pressed)

jinhui son
Tera Contributor

function onClick() {
    
    var gr = new GlideRecord('incident');
    gr.addQuery('sys_id',current.sys_id);
    gr.query();
    
    while(gr.next()) {
        gr.u_disability_report='true';
        gr.update();
    
    }
    action.setRedirectURL(current);

}

 

If I click the button on the form, I want to update the "u_disability_report" field value to true.

However, the field value is not updated even when the button is pressed.
Do you know the solution?

1 ACCEPTED SOLUTION

palanikumar
Giga Sage

Hi,

I think you checked "Client" Check box in UI Action, Uncheck it. You can use the below script to update current record in UI Action

action.setRedirectURL(current);
current.u_disability_report = true;
current.update();
Thank you,
Palani

View solution in original post

7 REPLIES 7

Thanks for your help.
I did it your way, and it works well.

Ankur Bawiskar
Tera Patron

Hi,

I assume you have marked Client checkbox - True

On click - onClick()

Update script as this

function onClick() {

	var gr = new GlideRecord('incident');
	gr.addQuery('sys_id', g_form.getUniqueValue());
	gr.query();
	if(gr.next()) {
		gr.u_disability_report = 'true';
		gr.update();    
		location.reload(true);
	}
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for your help.
I did it your way, and it works well.