Last Work Note

Jhon Anthony
Kilo Contributor

Hi 

How to get the last work note of the incident and add it to the 

short description of the incident 

Need Help!!!

Thanks

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello JHON,

You can use the code given by sachin as well but it will give output as :

                2019-07-12 00:21:08 - System Administrator (Work notes)Code for work note update

My approach is as below:

1. You can create a AFTER UPDATE Business Rule with below configuration.

find_real_file.png

 

2. Scrip in Business Rule:

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var grInc = new GlideRecord('sys_journal_field');
grInc.addQuery('element_id',current.sys_id); // Adding filter to find current incident
grInc.addQuery('element','work_notes'); // Adding filter to fetch only Worknotes
grInc.orderByDesc('sys_created_on');
grInc.query();
grInc.next();
current.short_description = grInc.value ;
current.setWorkflow(false); // Stop Running Business rule recursively as we have used current.udpate();
current.update();


})(current, previous);

 

Please mark answer correct if you found it as helpful.

Thanks,

Abhishek

Thank you,
Abhishek Gardade

View solution in original post

2 REPLIES 2

sachin_namjoshi
Kilo Patron
Kilo Patron

you can write business rule to get last work note and add to short description 

you can use below script

 

current.short_description = current.work_notes.getJournalEntry(-1);    // -1 for all the work notes value , 1 for latest work notes value

 

Regards,

Sachin

AbhishekGardade
Giga Sage

Hello JHON,

You can use the code given by sachin as well but it will give output as :

                2019-07-12 00:21:08 - System Administrator (Work notes)Code for work note update

My approach is as below:

1. You can create a AFTER UPDATE Business Rule with below configuration.

find_real_file.png

 

2. Scrip in Business Rule:

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var grInc = new GlideRecord('sys_journal_field');
grInc.addQuery('element_id',current.sys_id); // Adding filter to find current incident
grInc.addQuery('element','work_notes'); // Adding filter to fetch only Worknotes
grInc.orderByDesc('sys_created_on');
grInc.query();
grInc.next();
current.short_description = grInc.value ;
current.setWorkflow(false); // Stop Running Business rule recursively as we have used current.udpate();
current.update();


})(current, previous);

 

Please mark answer correct if you found it as helpful.

Thanks,

Abhishek

Thank you,
Abhishek Gardade