Copy Close Notes from a wm_task to a cloned wm_task

Anderson_R
Tera Contributor

The logging statements in my script confirm the retrieval of the associated 'wm_task' record and the identification of the value for 'current.close_notes'. Despite these verifications, the transfer of 'current.close_notes' string value into 'gr.work_notes' doesn't seem to occur as intended. I'm seeking advice on whether there's a more effective method to facilitate this transfer within the context of an After Update Business Rule.

 

(function executeRule(current, previous /*null when async*/) {
    var currentSysId = current.sys_id; // Get the sys_id of the current record

    var gr = new GlideRecord('wm_task');
    gr.addQuery('cloned_from', currentSysId); // Query for wm_task records where cloned_from matches the current sys_id
    gr.query();

    if (gr.next()) {
        // Access the related wm_task record with the same sys_id in cloned_from field
        gs.info('Related wm_task record found: ' + gr.getValue('number'));
        // You can perform actions on the related record here
        
        // Check if the close_notes field has a value before copying it to work_notes
        if (current.close_notes) {
            gs.info('Value of close_notes field: ' + current.close_notes);
            
            // Copy close_notes from the current record to work_notes of the found record
            gr.work_notes = current.close_notes;
            
            // Update the found record to save the changes
            gr.update();
        } else {
            gs.info('close_notes field is empty.');
            // Handle accordingly if close_notes is empty
        }
    }
})(current, previous);

 

 

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

It should work. Can you try with below script?

Also is it entering the script when you save the ticket?

gr.work_notes = current.getValue('close_notes');

 


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

It should work. Can you try with below script?

Also is it entering the script when you save the ticket?

gr.work_notes = current.getValue('close_notes');

 


Please mark this response as correct or helpful if it assisted you with your question.

Thank you @SanjivMeher!
getValue was the solution!