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

Voona Rohila
Kilo Patron
Kilo Patron

Hi , Try this in your UI Action code

function saveDesc() {
    var desc = g_form.getValue('description');
    g_form.setValue('description', desc);
    gsftSubmit(null, g_form.getFormElement(), 'save_dec'); 
}
if(typeof window == 'undefined')
runBusRuleCode();

//Server-side function
function runBusRuleCode(){
current.update();
gs.addInfoMessage('You did it!'); //testing
action.setRedirectURL(current);
}
	

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

You should verify if any of the values in form are modified or not, if yes then clear the value.

check below links

https://servicenowguru.com/scripting/business-rules-scripting/checking-modified-fields-script/

https://community.servicenow.com/community?id=community_article&sys_id=935c6aa1dbd0dbc01dcaf3231f961...


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

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);

 

this is not working with Additional Comments (Journal Input) type field on my form.

I want to update Additional Comments field only with current additional comments field value