Populate parent number in task field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 04:55 AM
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:
Any suggestions would be greatful. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 05:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 05:22 AM
Tried with the above script, but still not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 05:37 AM
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?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader