How to check Work Notes has been updated or changed in server side

ajayr
Giga Expert

Hello Guys,

I have a requirement where I need to send the WorkNotes of Incident from Snow to Remedy.

I am using getJournalEntry(1) to get the last updated work notes and send it to Remedy, till that it is fine.

Now if the WorkNotes is not updated still getJournalEntry(1) will send the same last updated work notes to Remedy, thus making duplicate entries in Remedy.

I wanted to know, How can we check whether WorkNotes has been updated or not. If there is no worknotes then nothing should be sent to Remedy.

FYI: I used current.work_notes.changes(), but that didn't work

14 REPLIES 14

Hi Ajay, If you want to build something that is future proof, I suggest you to look at the comments and work notes field inside UI 16 (Geneva and Helsinki). Inside of these instead of saving and updating the whole record, you simply post the comment or work note, so you are not updating the whole record but only creating a journal entry.



2016-06-05_00-02-48.png



So, inside UI16 you will most likely need to have a script that sends only the work notes and/or comments and a script for the record information. This script could be build using the when to run filter on business rule.



As for your current scenario if you are ok with not being future proof, work_notes and comments are journal field. Which means that before update they hold the value inside the current object and, on save, the value if posted to the journal.



So to check if work notes changes you can use:



if(current.work_notes != '');


You can forget about the whole future proof thing, as using the "Post" button stills update the record. So in your case a work note added using "Post" would send the whole record as it is stored in the database (modification unsaved would not be sent) + the work note added.


Hi Laurent,



if(current.work_notes != ''); will not work as we cannot hold the value to check whether it is empty or not. As already explained by you that it is a journal field. So I think we need to find other way. Like I was thinking to create a custom (date) field on Journal table and map with the updated date of task table. In this way we will get the exact value whether work_notes was entered or not.


But I can't do that right now as this will be a change in existing functionality. So need to find other solution.



Let me know if you agree with me.



Thanks,


Ajay


In fact, current.work_notes works but only with an On Before Business rule. The current object hold the work_notes until it is saved in the journal on save, so On After you don't have access to it anymore. However, the script action is run on after, so you are right, you don't have access to it.



I usually use Business Rules but I understand you probably have your reasons to use Script Actions.



Looking in the the event logs, I saw the event text_index with a parm1 of [work_notes] and the table incident when updating the work_notes. However this event is not registered so to use it you should register it in System Policy -> Events -> Registry



So you would have to make a seperate Script Action to send only the work notes. You could try to look if a work_notes text_index event has been created at the same time as the incident.updated event however when I tried to do so, I was unable to make something accurate as my script action running on the incident.updated event did not have a time stamp defined when running the Script action (event.sys_created_on was undefined inside the script include).



Here is what I have done if you would like to have a script action that sends only the work notes:



2016-06-05_11-27-50.png



So when a text_index event related to the table incident and the field work_notes is triggered, this script action takes the latest work_notes and put it in the log in my case but you would probably send it using your Script Include.


rashmi508
Kilo Contributor

Hi Ajay,


Were you able to find solution for this approach ?


Even i have same type of requirement where in i need to check whether the work notes is updated or not without writing business rule.