Updating work notes of SCTASK when a field is updated in RITM

sankon
Kilo Expert

Hi, I have a requirement where a field is modified in RITM, work notes have to be added in SCTASK with that information.

I have added the following "before" business rule for "insert" and "update" on sc_req_item table

-------

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

// Add your code here
var list = current.fieldName.getDisplayValue();
current.work_notes = "fieldName has been modified to " + list;

var grTaskList = new GlideRecord("sc_task");
grTaskList.addQuery('request_item', current.sys_id);
grTaskList.query();

while(grTaskList.next()){
grTaskList.worknotes = "fieldName has been modified to 1 \n" + list;
//grTaskList.update(); - added this upon a suggestion from another sample
}

})(current, previous);

but I see the following

find_real_file.png

the work notes are being added to the top and not in work notes under Activities. Please let me know of any suggestions.

Thank you!

1 ACCEPTED SOLUTION

Mario Quinones1
Mega Guru

Change:

grTaskList.worknotes = "fieldName has been modified to 1 \n" + list;

 

for:

 

grTaskList.work_notes.setJournalEntry("fieldName has been modified to 1 \n" + list);

 

Please mark as accepted solution if correct

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

This is really hard to follow what is happening/not happening with such a limited area on the screen shot and all of the redacting - can't you mock up some data that doesn't require obfuscation?  A before Business Rule running on the sc_req_item will need the grTaskList.update(); line or else the sc_task field changes will not take effect - unless you have another client script or business rule that is affecting this update.  Your current.work_notes line doesn't make sense unless you also intend to update the RITM with a work note.  So with the update() line added, what is it that you see on catalog task(s) when a field is modified on the RITM? I'm not following what 'added to the top' means.  On your form layout for sc_task, which is the partial form I assume is shown, what is it that you have just before the Work notes field?

Mario Quinones1
Mega Guru

Change:

grTaskList.worknotes = "fieldName has been modified to 1 \n" + list;

 

for:

 

grTaskList.work_notes.setJournalEntry("fieldName has been modified to 1 \n" + list);

 

Please mark as accepted solution if correct

sankon
Kilo Expert

Sorry about the incomplete screenshot. 

Combination of uncommenting grTaskList.update();

and

grTaskList.work_notes.setJournalEntry("fieldName has been modified to 1 \n" + list);

worked and shows the update in work notes but I am still seeing the update also displaying on the top as well. So, there are duplicate entries for the same in two places. Is there anyway for the update not to show up on the top or is this working as designed? Appreciate it.