Capture Worknotes and additional comments values into custom field

Ramakrishna6
Tera Contributor

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.

 

1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

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 :-

GunjanKiratkar_0-1668593126056.png

 

(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

View solution in original post

2 REPLIES 2

Saurav11
Kilo Patron
Kilo Patron

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.

Gunjan Kiratkar
Kilo Patron
Kilo Patron

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 :-

GunjanKiratkar_0-1668593126056.png

 

(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