How to update worknotes from script in flow designer ?

Thej1
Tera Expert

Hi,

I am trying to update the Work notes of incident from the flow designer. Somehow it is not updating the worknotes when triggered.

Here is the script

 

(function() {
    
    var workNotes = '';

    if (fd_data.trigger.previous.assigned_to) {
        var assignedToGr = new GlideRecord('sys_user');
        if (assignedToGr.get(fd_data.trigger.previous.assigned_to)) {
            var assignedToName = assignedToGr.name.getDisplayValue();
            
            
            workNotes = 'Dear ' + assignedToName + ',\n\n' +
                'Please note that the customer has escalated this incident. The ticket has been reassigned to the ABCD for further handling. The ABCD will reach out to the team lead to clarify the situation and agree on a resolution plan.\n\n' +
                Best regards
        }
    }

    
    if (workNotes) {
        fd_data.current.work_notes = workNotes;
    }

    return fd_data.current.work_notes;

})();

 

 

 

 

 

Please help me on this.

 

Thanks

@Community Alums @Sohail Khilji @Sid_Takali 

7 REPLIES 7

What does your flow execution say? 

You could add logging to see where the issue is. Can you confirm that you do have that previous assigned_to?

You could make this the script:

(function() {
   
    var workNotes;
    var assignedToName;
    if (fd_data.trigger.previous.assigned_to) {
        var assignedToGr = new GlideRecord('sys_user');
        if (assignedToGr.get(fd_data.trigger.previous.assigned_to)) {
            assignedToName = assignedToGr.name.getValue();
        } else {
            assignedToName = 'undefined';
        }
    }
    workNotes = 'Dear ' + assignedToName + ',\n\nPlease note that the customer has escalated this incident. The ticket has been reassigned to the DISC for further handling. The DISC will reach out to the team lead to clarify the situation and agree on a resolution plan.\n\nBest regards,\nJarvis';
    }
    if (workNotes) {
        return workNotes;
    }
})();

This should fill your worknotes no matter what and gives you a clue into where to look.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark,

 

I have kept logs and checked. It is not getting the value of previous.assigned_to as does in Business Rule.

Hence, created a new field on incident form and stored previous assigned to from BR.

Then tested. In logs i can see that worknotes is correctly constructed but not updating in ticket. Them removed function from code and tested. Then worked fine.

 

Thanks 🙂

So removing the last 'if' did the job?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark