How to update only one field using UI action

ChaitanyaKanuri
Tera Expert

Hi ,

I am trying to create an UI action to update only one field. I tried using the below code 

function saveDesc() {
    var desc = g_form.getValue('description');
    g_form.setValue('description', desc);
    gsftSubmit(null, g_form.getFormElement(), 'save_dec'); 
    action.setRedirectURL(current);
}

 Action Name  : save_dec

I am bale to save if i added the value of the description in the setvalue method. But if I am trying to get and set it is not working as expected. and after this script the page should be redirected to the same form page.

 find_real_file.png

Can someone help me out.

 

Thanks.

1 ACCEPTED SOLUTION

ChaitanyaKanuri
Tera Expert

I got the solution,

Instead looking for client side solution we can do it via server scripting via GlideRecord.

current.update is updating all the fields. so using below code we can get the solution.

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

 

View solution in original post

9 REPLIES 9

Pedro Grilo1
Mega Sage

Hi!

 

Can you add a screenshot of the entire UI Action?

 

Best regards,

Pedro

Added the screeshot of the UI action.

Deepak Negi
Mega Sage
Mega Sage

Hi

 

The code is incorrect. action.setRedirect is supposed to be inside the server script instead of client function.

 

However if you only need to update the field then no need to make the UI action to be run as Client first.

1. Uncheck the Client checkbox

2. Write below code to update the description:

current.description  = "Any value"
current.update();
action.setRedirectURL(current.getLink());

 

For more information on how client and server side code works in UI action, please follow:

https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action

 

Please mark this answer correct/helpful if it helps.

 

Thanks

Deepak

Hi @Deepak Negi ,

TRhis will work but If made any change to anyother fields those will also get updated. I want to update the description field only.