- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Hello Community Members,
Learning from community and giving back to it is my favourite part of day to day activity. As a result I have created blog regarding calculated Value field which we can use anywhere when we requires to implement any logic based on fields or based on own logic.
Problem Statement :- Get Latest Work note or Additional Comment into the custom field automatically.
Implementation :-
1. Create a custom field on incident form as type string.
Fig. New String Field
2. Go to the Configure Dictionary and click on advance view from related links.
3. Navigate to the Calculated Value tab and check the checkbox as true.
4. In the Script Section write down below script to get the new value from journal entry either it will be Work note or Comment.
Fig. Calculated Value Code
(function calculatedFieldValue(current) {
// Add your code here
var je = new GlideRecord('sys_journal_field');
je.addEncodedQuery('element=work_notes^ORelement=comments');
je.addQuery('element_id', current.sys_id.toString());
je.orderByDesc('sys_created_on');
je.setLimit(1);
je.query();
if (je.next()) {
return je.value.toString();
}
})(current);
Demo :-
If we check initially the field is empty as we don't have any work note or comments added for record.
Fig. Field Before adding any comment/work note
As soon as we post the work note and reload the page the field will pop up with the work note value.
Fig. Field After add work note
Now I have post the comment and reload the page so it will take the content of comment from the Journal Entry.
Fig. Field After adding comment
Note :-
1. Calculated Values are always read only as it gets values from script.
2. It reflect values on Load of form.
Implementation Video :
Value added in your knowledge ??? Then please mark it as helpful, bookmark it for future use and also share it with your ServiceNow squad.
Regards,
Gunjan Kiratkar
Community MVP 2023
Community Rising Star 2022
Youtube : ServiceNow Guy
- 16,902 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.