Question

How to get logging agent as an email placeholder


Userlevel 3
Badge +4

I am trying to get the name of the logging officer into a placeholder (Freshservice does not have such a field!) To do this I am using the Fresh v2 web API. To do this I am doing a GET request to https://sjchh.freshservice.com/api/v2/tickets/{{ticket.id_numeric}}/activities

This is getting the activities fine, and it picks up the name of the agent for each activity under $.activities[*].actor.name

Unfortunately, my plan of getting it out of $.activities[0].actor.name as the first recorded activity doesn’t work because Fresh returns the JSON array in order of last activity to first activity. 

Does anyone know how to get the highest indexed activity? So I have six activities, the highest indexed activity would be number five, so I want to access $.activities[5].actor.name

 

 


15 replies

Userlevel 7
Badge +11

Hello, 

 

You can use -1 to get the last item in the array. 
More info here JSONPath - XPath for JSON (goessner.net)
Here are some “hidden” placeholders List of Dynamic Placeholders : Freshservice

But I think you are looking for {{event_performer_email}}

 

 

Userlevel 3
Badge +4

I just tried the -1 trick to get the last person, but Fresh returns “true”. Also returns “true” for {{event_performer_email}}

 

Any ideas?

Userlevel 7
Badge +11

I just tried the -1 trick to get the last person, but Fresh returns “true”. Also returns “true” for {{event_performer_email}}

 

Any ideas?

Can  you post a screenshot of your JSON node setup ? 

Userlevel 3
Badge +4

 

Userlevel 3
Badge +4

So… it’s odd. On the left hand side, you can see that name is a string, but on the right hand side it says it is an array of strings. Actually, name it is not an array of strings... activities is an array of objects, but actor, actor.id, actor.name, content and created_date are not arrays. 

Userlevel 7
Badge +11

So… it’s odd. On the left hand side, you can see that name is a string, but on the right hand side it says it is an array of strings. Actually, name it is not an array of strings... activities is an array of objects, but actor, actor.id, actor.name, content and created_date are not arrays. 

The type is what the JSON parser think it is, it’s not perfect. You can change it if you think it. 
The Placeholder will behave different depending the type. Some nodes only accept placeholders that are a string. 
In some cases I have run 2 JSON nodes after each other to get the correct value. 

If you wish to get the e-mail in the end you need to get the ID and not the name. 
Then match the ID using the agent API endpoint.  



 

Userlevel 3
Badge +4

It does appear that JSON parser is not detecting the type correctly. I have logged a support ticket to have this investigated.

Your idea about getting the agent has merit, I’ll look into doing this, but it does mean extra calls to the Fresh API.

Userlevel 3
Badge +4

FWIW, I changed the test case to access element 0 of an array of strings, and Fresh returns nothing. This looks like a bug.

Userlevel 7
Badge +11

FWIW, I changed the test case to access element 0 of an array of strings, and Fresh returns nothing. This looks like a bug.

Hmm, strange I have had no issue with this. what do you get for result on the right side (Click on view..) when you add -1 on this line?
 

 

Userlevel 7
Badge +14

Hello @Chris Sherlock, are you simply trying to get the name of the person who created the ticket? I can share how we have solved that problem for a few usecases, mainly for reporting purposes but it may work for your case as well.

It takes a bit of setup in the beginning but then runs and gives us a “Created By” hidden text field filled with the agent’s name who created the ticket that you can then access in workflow if necessary.

Let me know if you are interested in this solution :) 

Take care!

Userlevel 3
Badge +4

@zachary.king absolutely! I would love to know :-) It seems crazy Fresh doesn’t record this...

Userlevel 3
Badge +4

@daniel.soderlund unfortunately, it’s any access to an array returns nothing for me. Fresh support have just told me that they reproduced this in their environment and it is a bug. 

Userlevel 7
Badge +11

@daniel.soderlund unfortunately, it’s any access to an array returns nothing for me. Fresh support have just told me that they reproduced this in their environment and it is a bug. 

Hmm, strange I just replicated this in a trial 
I’m using -1: in the JSON path, it gives me the oldest only 

 

 

Userlevel 7
Badge +11

If I use 0 I get the latest 
 

 

Userlevel 7
Badge +14

@zachary.king absolutely! I would love to know :-) It seems crazy Fresh doesn’t record this...

I agree, especially since it is available in Freshdesk. But...with a little intuition we can replicate the behavior. 

So here are the steps:

  1. Create a plain text form field and label it (ours is “Created By”)
  2. Using Business Rules for Forms, hide the field from agent view if necessary
  3. This is the meat and potatoes… Build a custom application that runs in the background of the new ticket screen. The application will be triggered when the agent clicks to create a ticket, the application calls the Freshservice API to get the “loggedInUser”’s name, Then using that value sets the value of the newly created text field with the agent’s name.
  4. Install the application into production and let it run for all newly created tickets moving forward

the Created By field now becomes a field you can report on and use in workflow

 

Let me know if you need some help with the building of the custom application. Hope that helps!

Reply