Skip to main content

Hi Community,

Has anyone had success with automatically associating multiple assets to a ticket based on the Requestor or Requested For using workflow automator/web request node?

We have certain service item that would benefit greatly from an automation like this.

Thank you,

Michael.

Hi

Depends on the specific use case you wish to solve I guess. It is for sure possible to add associate assets through web request. I have a flow that associates assets based the requested service item and use a custom object to manage the mapping of service items to applicable asset record.


Did you figure this out? I have a similar need. Most of our tickets are opened via email, and we want a workflow to associate any assets assigned to the requester to the ticket. Or, if not all assets, at least any Computers assigned to that requester. Right now our helpdesk is having to manually associate assets and this will save steps.

 

Webhook/API coding is pretty over my head, would anyone share the config that would accomplish this?


Hi Sarah,

I did work something out but it was a frustrating process and I see it as nothing more than a workaround to what I believe should be natively available in the toolset.

  1. Create a workflow with a trigger for type of ticket you want to automatically associate assets.
  2. First you want to find the associated assets of the user by using the web request node. Make a GET request to the endpoint to grab the assets (will need to have an encoded URL using a filter).
    1. Example: https://domain.freshservice.com/api/v2/assets?filter=%22user_id%3A%20{{ticket.actual_requester.id}}%22
  3. Then you want to use the JSON Parser node to grab the web response body.
  4. Then you want to create some custom json.path expressions to pull the display_id of the asset

  5. Use an action node to copy the expression to a ticket field

    1. (I created string fields for the ticket that have business rules to always hide them from agents and requesters.)

  6. I iterate through each field (I went to a total of 6 as it’s unlikely in our environment for a requester to have more than a few assets assigned to them) and based on those conditions, run a web request to associate the asset to the ticket

 

I was also very daunted by API, Web Requests and not really developer minded. I am sure there is a more elegant solution and I would love to see this just available as an admin setting in Freshservice. However, this is where I landed after literal weeks of back and forward with support.


Good Stuff

Depending on your use case @sarahkek and I would heavily caution against doing a sort of blanket application of this.  If you start to add in different servers, etc, you could end up with misattributed assets on tickets which would pollute your data when it comes time to crunch numbers. For example, I have device 1 assigned to me, but I email a ticket that FreshService cannot be accessed.  My device is attached to the ticket, when really the “problem asset” is that FS is down for maintenance.  An automation such as this could introduce a lot of garbage data if you dont put proper precautions into place to ensure that the right asset is being assigned (perhaps description contains “my computer” or “my asset” etc as a first line condition after the trigger?).

As an aside @MichaelS24 I just had FS support tell me this morning that there wasn’t a way associated assets to a ticket via the API in a workflow, but your code looks like it would do just that. Thanks for making my day!  If you are having a problem with the API/Web Requests in the future feel free to hit me via PM, I definitely owe you one :)


Thank you so much Michael. You’ve given me a jump start into the API world.  

I’m stuck on the last step, the Web Request to update the asset. On validation, it’s indicating that it tries to update a custom dropdown field on the ticket, rather than the assets on the ticket.  Appreciate any insight into what’s gone wrong.

 

This is what I have configured so far:

 

Closer view of the JSON Output step:

​​​

 

Closer view of the Action step:

 

Closer view of the final Web Request step which is giving a validation error indicating that it’s trying to update a custom dropdown field...

 

The validation error is:

{
  "description": "Validation failed",
  "errors": f
    {
      "field": "custom dropdown field on ticket]",
      "message": "It should be one of these values: 'hlists the possible values of that field]",
      "code": "invalid_value"
    }
  ]

 

 

@Medic I understand your caution about associating assets that aren’t actually related to the issue in the ticket. We’ll keep that in mind, thank you!

 


@sarahkek there’s probably a mandatory field (not related to what you are trying to update) on the ticket that needs populated in the Ticket Form Field settings. The “require on update” being checked on that field in the ticket form fields means that even when it is populated, if interacting via the API you must also pass a value to it.  If this is what is stopping you, add ?bypass_mandatory=true to the endpoint that should get you past it. 

A protip I have from an admin perspective is to use Business rules in lieu of form field requirements as they will provide the GUI level enforcement of requirements for users and you can skirt the requirements as an admin when doing web requests (depending on the use case) :)

 

Example: https://blank.freshservice.com/api/v2/tickets/{{ticket.id_numeric}}?bypass_mandatory=true


@Medic1334 That was exactly it, it was a required field.  Thank you both!  This will be a big help to our front line. @MichaelS24 

 

Also, for anyone needing this solution in the future - I ended up making the initial asset query a little more specific so that it will only grab the requester’s laptop or desktop, instead of everything assigned to them.


https://DOMAIN.freshservice.com/api/v2/assets?filter=%22user_id:%20{{ticket.actual_requester.id}}%20AND%20(asset_type_id:%20DESKTOP ASSET ID%20OR%20asset_type_id:%20LAPTOP ASSET ID)%22
 


@medic1334 & @sarahkek - I am glad this worked for you. I will put this here to keep in your pocket should the need arise as well.

Use case: I wanted an end user’s assets to be in the description field so that when an approval was sent to someone relating to their asset, they could see confirm the asset at first glance of the approval. 

Achieved this by following private note using liquid filters:

{% assign asset_name = {{P2.root.assets.assets_object.name}} %} {% assign asset_name = asset_name | remove: ':' | remove: ']' | remove: '"' %} {% assign asset_name = asset_name | split: ',' %}

{% assign asset_type = {{P2.root.assets.assets_object.asset_type_id}} %} {% assign asset_type = asset_type | remove: ':' | remove: ']' | remove: '"' %} {% assign asset_type = asset_type | split: ',' %} 

{% for type in asset_type %}

{{ type | replace: "75000416027","Laptop" | replace: "75000416007","Computer" | replace: "75000416026","Desktop" | replace: "75000454420","Android" | replace: "75000416033","iPad" | replace:  "75000416032","iPhone" | replace: "75000416011","Monitor" | replace: "75000416015", "Router" | replace: "75000420262","MobilePlan" | replace: "75000454421","MBBDevice" }}: {{ asset_name_forloop.index0] }}


{% endfor %}

 

Then using another web request I place it in the description

{
"description": "{{ticket.latest_private_comment | replace: "System", "Assets" | remove_first: " " | sanitize_html}}",
}
 

Love the idea to further filter the web requested by specifying the asset type - nice one!


I’m not sure I understand what your code is doing… is the below accurate?

In an add private note action:

  1. Sets the value asset_name as {{P2.root.assets.assets_object.name}} then removes the brackets and quote marks then splits them at the comma
  2. Does the same but for each type
  3. Runs a loop(or a foreach if you will) against each device type from point 2 that changes the device type to the human friendly name from the asset type number

Once the private note is posted, the web request/API put action inserts the contents into the description on the ticket (since you cannot insert the value via actions for a reason I cannot fathom but hopefully they fixed it)


Reply