Populate parent number in task field

Anshu56
Tera Contributor

When user is a member of Policy team group and creates a ticket in portal then a field approval skip visible to user with 2 options yes or no. if user is not member of that group then that field not visible. After submitting the ticket in portal, when open that ticket in self service, A hr_task is attached to that ticket. in that task a field called HR Parent case is empty which will be autopopulate with Parent ticket number (this is not working). I created a BR to autopopulate the field with Parent ticket number, but it's not working.
Note: If user is not member of that group and submits the ticket, in this case approval is triggered after that hr task is attached and the field also autopopulate with parent number. 

After Insert, Update BR.
Script:

(function executeRule(current, previous /*null when async*/) {
   if (current.parent) {
     var parentTicket = new GlideRecord('hr_staff_management');
    if (parentTicket.get(current.parent)) {
       if (parentTicket.u_approval_skip == 'Yes') {
       if (current.staff_parent_hr_case != '') {
         return; 
         } else {
gs.info("Populate parent ticket number");
         current.staff_parent_hr_case = current.parent.toString();
 
        }
      }
}
  //current.u_staff_parent_hr_case = current.parent;
})(current, previous);

Anshu56_0-1690804468293.png

Any suggestions would be greatful. Thanks


 

3 REPLIES 3

Tushar
Kilo Sage
Kilo Sage

Hi @Anshu56 

 

Please try below script - 

(function executeRule(current, previous /*null when async*/) {
    if (current.parent) {
        var parentTicket = new GlideRecord('hr_task');
        if (parentTicket.get(current.parent)) {
            if (parentTicket.u_approval_skip == 'Yes') {
                if (current.staff_parent_hr_case == '') {
                    gs.info("Populate parent ticket number");
                    current.staff_parent_hr_case = current.parent.toString();
                    current.setWorkflow(false); // To prevent triggering the Business Rule again on update
                    current.update();
                }
            }
        }
    }
})(current, previous);

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

Tried with the above script, but still not working

Ankur Bawiskar
Tera Patron
Tera Patron

@Anshu56 

Did you debug the BR and check if it's triggering or not?

Also did you debug by adding gs.info() and check code is working till which point?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader