Getting an Email from a Person attribute

I have a form where the user selects an "affected account" which is a person attribute. Then, I have a workflow that needs to send a notification, and the notification body must include the email of the "affected account". However, the person field seems to only include display name. I've seen threads on here implying you can do a person API lookup to get the email from the display name, but there are two problems with that: 1. the display name might match multiple people's names and 2. the response from the API person search contains much more than just the email. If this were a script, I could easily parse out the response, but how can I do that in a workflow?

Is there any solution to my problem here?

Thanks for the help,  

Tags API workflow people
Asked by Tamara Buch on Mon 10/23/23 12:30 PM Last edited Mon 10/23/23 4:28 PM
Sign In to leave feedback or contribute an answer

Answers (2)

This answer has been marked as the accepted answer
Tamara Buch Wed 10/25/23 12:28 PM Last edited Wed 10/25/23 2:27 PM

To all who find this thread with a similar issue... I was able to parse the user's email out of the person type custom attribute in one API call using the Notify section of the response body.

Syntax for the "from workflow" parameter: Response.Notify[?(@.ItemRole=~/^(.*, )?Custom Attribute Name(, .*)?$/)].Value

Where Response is the name of value you're storing your GET ticket API call response in (defined in the workflow) and Custom Attribute Name is the full name of your custom attribute. 

The workflow is as such:  

1. Workflow step to call web method GET TDX TICKET, storing response as Response

2. Workflow step to call web method of your choice

3. In web method of your choice, use 'From Workflow' parameter Response.Notify[?(@.ItemRole=~/^(.*, )?Custom Attribute Name(, .*)?$/)].Value and with Name "EmailOfUser" (or name of your choice) and then using {{EmailOfUser}} in your web method somewhere. 

See attached picture. 

NOTE: The reason for using =~/^(.*, )?Custom Attribute Name(, .*)?$/ (regex substring match using wildcards) instead of a hard == (exact match) is because if the person selected in the custom attribute is the same as any of the other roles on the ticket (requestor, responsible, etc) their ItemRole name will be something like "Responsible, Requestor, Creator, Custom Attribute" rather than just "Custom Attribute". We also do not want to match "Custom Attribute Name 2" or "Test Custom Attribute Name" 

No feedback
Also all of the syntax here is using JSONPath if that helps troubleshoot your own API response parsing. - Tamara Buch Wed 10/25/23 12:31 PM

Mark Sayers Mon 10/23/23 12:59 PM

Hello Tamara,

You would be better off just GETting the ticket itself, then refer to that response body to get the UID value from that custom attribute and do your user call from there to get their user account via UID and retrieve the email value from *that* call's response body.

Sincerely,
Mark Sayers
Sr Support Consultant, CS

1 of 1 users found this helpful.
Hey Mark,
Thank you for the quick response! Do you have some documentation or examples of working with the response body in a workflow? I'm very familiar with doing this in Powershell/Python, but it's unclear on how to use just one part of the larger response body within a TDX workflow.
- Tamara Buch Mon 10/23/23 2:53 PM
https://solutions.teamdynamix.com/TDClient/1965/Portal/KB/ArticleDet?ID=148498

I found this which seems like exactly what I need :)
- Tamara Buch Mon 10/23/23 3:54 PM
Yep I think that would get you pretty close to it. Let us know if you end up having specific questions or trouble when trying to set that scenario up. - Mark Sayers Mon 10/23/23 4:04 PM
Mark, thank you. I am actually having trouble on the last step. I've edited my question to include a screenshot. It's unclear to me how to reference the value in the response that I need. - Tamara Buch Mon 10/23/23 4:29 PM
You're trying to reference the value of a custom attribute in the previous web service method, that would look something like this: GetTickRespBody.Attributes[?(@.ID==123456)].Value

Where 123456 is the attribute ID of your custom person attribute. Also, you might have to use something other than the "Value" property of that attribute's JSON response if that isn't the one that contains the UID of the selected person.
- Mark Sayers Mon 10/23/23 4:48 PM
Unfortunately it doesn't look like email is a property of a person attribute, the only place the email comes through is in the Notify section of the JSON response.
Below is how the attribute looks when returned by the GET ticket API call. As you can see.. no email ):

..."Attributes": [
{
"ID": 5308,
"Name": "UIUC-TechSvc-CSOC Affected Account",
"Order": 0,
"Description": "",
"SectionID": 0,
"SectionName": null,
"FieldType": "person",
"DataType": "String",
"Choices": [],
"IsRequired": false,
"IsUpdatable": true,
"Value": "8d407624-91c9-ea11-a81d-000d3a8ea9f7",
"ValueText": "Tamara Buch",
"ChoicesText": "",
"AssociatedItemIDs": [0]
},...

So is there another way to go about this through the Notify section? I tried to jimmy your syntax to match what I'm seeing but that didn't work either.
I tried: Response.Notify[?(@.ItemRole==UIUC-TechSvc-CSOC Affected Account)].Value
- Tamara Buch Tue 10/24/23 11:08 AM
Right, but you *can* get their UID because it is stored in the Value property, you can use that to then GET their user record in a subsequent web service call where you can then get at their email values. - Mark Sayers Tue 10/24/23 11:46 AM
Ahh ok. I got it working the way you described. A lot of hoops to jump through to get there but it works! Thank you for your help.
You're sure there's no way to parse out the Notify section of the response? That would make this a lot simpler! The API calls take quite awhile to run within the workflow.
- Tamara Buch Tue 10/24/23 3:52 PM
I can't think of anything that would be reliable without using iPaaS, nope. And it's unfortunate that a custom person attribute doesn't contain/link to that data from the selected person too. Perhaps that could be an enhancement idea. - Mark Sayers Tue 10/24/23 3:55 PM
ACTUALLY I GOT IT TO WORK!!
Response.Notify[?(@.ItemRole=='UIUC-TechSvc-CSOC Affected Account')].Value
Now I can do it with just one API call! Yayyyy
- Tamara Buch Tue 10/24/23 3:58 PM