To autopopulate the worknotes of Interaction form to its User's Tasks worknotes

rishabh31
Mega Sage

User's task- INC & REQ records.pngDear Team,

Want to auto-populate the work notes of Interaction's User's Tasks (incidents/requests) when work notes of its associated Interaction is updated/saved. (attached screenshot is the Interaction record's user's task records) 

 

I tried to achieve this Before Insert Update BR on the Interaction table with the condition- Work notes changes, but not sure how to refer to Interaction's user's tasks records through advanced scripting so that when interaction work notes are updated then the same work notes will get auto-populated in its associated user's task records.

Please help to get this resolved.

Thanks in advance

1 ACCEPTED SOLUTION

BharathChintala
Mega Sage

@rishabh31 

BharathChintala_0-1678866734755.png

BharathChintala_1-1678866751160.png

Working solution tried in Personal instance.

 

Few things to clarify is Related tasks vs User's Tasks

 

Related tasks is which interaction is associated with and User's tasks are like all active incidents, change, problem and requests opened by interaction open by user.

 

So I have script to update work notes to related records if you want I can send script for User's tasks also.

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

View solution in original post

14 REPLIES 14

Thank you so much @OlaN Sir for all your time, I have learnt from this

BharathChintala
Mega Sage

@rishabh31 

BharathChintala_0-1678866734755.png

BharathChintala_1-1678866751160.png

Working solution tried in Personal instance.

 

Few things to clarify is Related tasks vs User's Tasks

 

Related tasks is which interaction is associated with and User's tasks are like all active incidents, change, problem and requests opened by interaction open by user.

 

So I have script to update work notes to related records if you want I can send script for User's tasks also.

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Now the work notes copied when somebody make a new comment. What to do if I want to copy all existing work notes when associating an incident? (copy only first time when associating) 

rishabh31
Mega Sage

@BharathChintala its working fine for related records, thank you so much, marked accepted solution & helpful.

 

Yes sir that will be great if this is for user's task, please share desired BR for user's task.

 

 

Thank you

@rishabh31 

 

Create new business rule same before on Interaction table and same on insert and update work notes changes

(function executeRule(current, previous /*null when async*/ ) {
    var callerID = current.opened_for;
    if (JSUtil.notNil(callerID)) {
        var inc = "active=true^caller_id=" + callerID;
        var prb = "active=true^opened_by=" + callerID;
        var chg = "active=true^requested_by=" + callerID;
        var scr = "active=true^requested_for=" + callerID;
        var incident = new GlideRecord('incident');
        incident.addEncodedQuery(inc);
        incident.query();
        while (incident.next()) {
            incident.work_notes = current.work_notes;
            incident.update();
        }
        var change = new GlideRecord('change_request');
        change.addEncodedQuery(chg);
        change.query();
        while (change.next()) {
            change.work_notes = current.work_notes;
            change.update();
        }
        var problem = new GlideRecord('problem');
        problem.addEncodedQuery(prb);
        problem.query();
        while (problem.next()) {
            problem.work_notes = current.work_notes;
            problem.update();
        }
        var request = new GlideRecord('sc_request');
        request.addEncodedQuery(scr);
        request.query();
        while (request.next()) {
            request.work_notes = current.work_notes;
            request.update();
        }
    }
})(current, previous);

 

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala