How to send delegated person email if user optied for delgation?

Manikantahere
Tera Contributor

I am integrating with third party for decision making as part of it I am sending the decision makers emails to them so that power automate will send the notification to them.

 

But what if the decision maker is already opted delegation then I should send delegate person mail instead original??

I also have another edge case what if the person opted delegation once after request already sent to power automate??

12 REPLIES 12

@Manikantahere 

Thank you for marking my response as helpful.

The script is easy.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Manikantahere 

something like this but please enhance

// Check for active delegation
var recipientUserId = 'user_sys_id'; // Replace with target user's Sys ID
var grDelegate = new GlideRecord('sys_user_delegate');
grDelegate.addQuery('user', recipientUserId);
grDelegate.addQuery('assignments', true); // Check if assignments are delegated
grDelegate.addEncodedQuery('ends>javascript:gs.daysAgoEnd(0)'); // Active end date
grDelegate.query();
if (grDelegate.next()) {
    var delegateUserId = grDelegate.getValue('delegate');
    // now you have delegate user sysId
    // you can use gs.eventQueue() to send email to that or use API
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Manikantahere 

If I'm not mistaken, once a delegation is given, the delegatee receives all the emails. This is my understanding, but only for new records. To test this:

Create a delegation in your instance, create a new record, and assign it to the user. Then, check if the delegatee is receiving the email. If yes, no further confirmation is required.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Actually for the approvals we are sending team notifications/outlook mails to approvers via power automate before sending them we are not validating whether he opted delegation or not but now we need to check if he not opted delegation then we can send his details directly to the power automate but if he opted delegation I need to send delegated person details if the trigger is happening with in the delegation duration.

How can we achieve this through script?

Even if we achieve this through script sometimes approver might opt delegation once he got the approval notification? can we address this through script?

Hi @Manikantahere 

In this case, you need to check two things:

  1. Go to the delegation table.

  2. Verify if the user record is present.

    • If yes, check the start date and end date, and compare them with the current date.

    • Then check if the notification has been triggered (ticket created or not).

    • Finally, retrieve the delegate's name.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************