Add users assets into an email

Alex Saager1
Tera Contributor

Hi Community,

 

We have a flow setup that will email a person's line manager a few days before their leave date and I want to add the leavers assets into the email, can anyone adivse on the best way to achive this as at present we can only get one asset returned.

Here is the flow:

AlexSaager1_0-1749632838483.png

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Alex Saager1 

you can use a flow variable and concatenate the assets of that user by iterating using For Each

Then in single email use that flow variable to print all the assets

check how you can append/concatenate the assets in flow variable using For Each

flow variable iterate and append for the for each.gif

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

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

@Sandeep Rajput  @SANDEEP DUTTA  @Mark Manders @Ankur Bawiskar  @Shivalika  any help here.

*************************************************************************************************************
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]

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

Mark Manders
Mega Patron

There are 2 ways to handle this. Either do a lookup to the asset table and get the assets of the user and add them to a string variable (update the variable for each found asset) and use the text from the variable in the 'send email' body. Or use the 'send notification' action and do a lookup to all assets within an email notification script and add that script to the body of your notification.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Ankur Bawiskar
Tera Patron
Tera Patron

@Alex Saager1 

you can use a flow variable and concatenate the assets of that user by iterating using For Each

Then in single email use that flow variable to print all the assets

check how you can append/concatenate the assets in flow variable using For Each

flow variable iterate and append for the for each.gif

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

J Siva
Tera Sage

Hi @Alex Saager1 
I believe you've set up your flow on the sys_user table. If yes, then you can try the below approach.
1. Create one email script to fetch all the assets which belongs to the current user.

    var emp = current.sys_id;
    var content;

    template.print('<table border="1"> <tr> <th>Asset ID</th> <th>Name</th><th>Custodian</th></tr>');

    var assets = new GlideRecord('alm_asset');
    assets.addEncodedQuery("assigned_to!=NULL^asset_tagISNOTEMPTY^assigned_to="+emp); // MODIFY THIS QUERY AS REQUIRED
    assets.query();
    while (assets.next()) {
        var str = '<tr> <td>' + assets.asset_tag + '</td> <td>' + assets.display_name + '</td> <td>' + assets.getDisplayValue('assigned_to') + '</td> </tr>';
        template.print(str);
    }
	
    template.print(' </table>');

JSiva_0-1749637392173.png

 

2. Create a notification with the "Send When" value is 'triggered'

JSiva_1-1749637504203.png

JSiva_2-1749637523101.png

JSiva_3-1749637559878.png

 

3. Call your notification in the flow using "Send Notification" action

JSiva_4-1749637628600.png

 

Result:

JSiva_5-1749637652634.png

 

JSiva_6-1749637667900.png

 

Hope this helps.
Regards,
Siva