- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 01:45 AM
I created new field "latest comments" on task table. Now i want to populate both 'Worknotes" and "Addtional comments" latest values into new(latest comments) field.
When i post sometning in "worknotes", new field should show "worknotes" value
When i post something in "Addtional comments", new field should show "Addtional comments" value
I achieved this through BR(Business rule), But currently I need client script for this.
I tried onchange client script, But i confused because in onchange client script it showing only one field name, but i need to mention both "worknotes" and "Addtional comments" values right
Please suggest client script for this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 02:06 AM
Hi @Ramakrishna6 ,
The best way I can see is to use calculate value feature.
enable calculate value in your custom field and use below script :-
(function calculatedFieldValue(current) {
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);
Goto Configure Dictionary of field - click on advance view from related links to enable calculated value.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 01:50 AM
Hello
If you have acheieved it through business rule why are you going to client script
If you use on chnage ckient script then you will need two onchange client script one for worknotes and one for additional comments.
If you only want to write one script then you will have to write a BR
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 02:06 AM
Hi @Ramakrishna6 ,
The best way I can see is to use calculate value feature.
enable calculate value in your custom field and use below script :-
(function calculatedFieldValue(current) {
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);
Goto Configure Dictionary of field - click on advance view from related links to enable calculated value.