Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Unable to Update Additional Comments field on a form using UI action

Abhilash Janga1
ServiceNow Employee
ServiceNow Employee

I have created a UI action, through that only the "Status" & "Additional comments" field should get updated. if i click the button without entering any "Additional comments" , error message should display. I have written below script in that UI action, its purely server side. Please if u can help me how can i update these two fields only. Rest all fields shouldn’t get updated even i select any value from them.

Script:

if (current.u_additional_comments == '') {
gs.addInfoMessage(current.u_additional_comments);
gs.addErrorMessage("Add Additional comments for Funds Released");
} else {
var comments = current.u_additional_comments;
var irt = new GlideRecord('u_money_request');
irt.addQuery('sys_id', current.sys_id);
irt.query();
while (irt.next()) {
irt.setValue('u_status', 'Money Released');
irt.setValue('u_additional_comments', comments);
irt.update();
gs.addInfoMessage("Status updated for approved Investment to Money Released Successfully");

}
}
action.setRedirectURL(current);

 

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

in script you are updating 2 fields

Did you check any business rule is updating other fields when the record gets updated via script?

Regards
Ankur

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

Hi Ankur ,

Thanks for replying. I have checked there is no any BR affecting this. The Additional Comments is Journal Input type field

Kartik Sethi
Tera Guru

Hi @Abhilash Jangam 

 

Put a log statement under the while loop and see if you are getting any logs:

if (current.u_additional_comments == '') {
    gs.addInfoMessage(current.u_additional_comments);
    gs.addErrorMessage("Add Additional comments for Funds Released");
} else {
    var comments = current.u_additional_comments;
    var irt = new GlideRecord('u_money_request');
    irt.addQuery('sys_id', current.sys_id);
    irt.query();
    while (irt.next()) {
        //Check if you are getting the below details in logs
        gs.info('[DEBUG] Comments found: ' + comments);
        irt.setValue('u_status', 'Money Released');
        irt.setValue('u_additional_comments', comments);
        irt.update();
        gs.addInfoMessage("Status updated for approved Investment to Money Released Successfully");

    }
}
action.setRedirectURL(current);

 

Please confirm.

Thanks and regards,

Kartik

Hi Karthik Thanks for reply.

Its populating the current Additional comments value if i put in while loop , but not updating the value for the field.

Updated Script:

if (current.u_additional_comments == '') {
gs.addInfoMessage(current.u_additional_comments);
gs.addErrorMessage("Add Additional comments for Funds Released");
} else {
var comments = current.u_additional_comments;
var irt = new GlideRecord('u_investment_request');
irt.addQuery('sys_id', current.sys_id);
irt.query();
while (irt.next()) {
irt.setValue('u_status', 'Funds Released');
irt.setValue('u_additional_comments', comments);
gs.addInfoMessage("Current Comment " + current.u_additional_comments);
irt.update();
gs.addInfoMessage("Status updated for approved Investment to Funds Released Successfully");

}
}
action.setRedirectURL(current);