Unable to Update Additional Comments field on a form using UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2022 09:37 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2022 09:39 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2022 09:49 PM
Hi Ankur ,
Thanks for replying. I have checked there is no any BR affecting this. The Additional Comments is Journal Input type field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2022 09:55 PM
Hi
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2022 10:10 PM
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);