Skip to main content
Question

Add relationship as part workflow


Forum|alt.badge.img+7
  • Skilled Expert
  • 31 replies

Hi,

 

Is it possible to automate creation of relationships as part of a workflow? For example if a user orders a service (not hardware/software) and I would like to track the fact that the user is consuming that service in CMDB for helpdesk to have that insight in case of incident etc.

Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+7
  • Author
  • Skilled Expert
  • 31 replies
  • July 28, 2022

So I think I solved this on my own by using the bulk create relationship API call. Not really a drag and drop kind of solution that I was looking for but at least it could be done.


Daniel Söderlund
Skilled Expert
Forum|alt.badge.img+14

Could you share the solution for the community ? 


Forum|alt.badge.img+7
  • Author
  • Skilled Expert
  • 31 replies
  • July 29, 2022

I will happily share my findings. Please beware that I’m a newbie in terms of Freshservice so it may definitely be other and better solutions for this out there.

I solved this by using a series of the “Web Request” nodes in the workflow. The api for creating relationships only work for agent and requesters separately so before triggering that action I need to find out if the person requesting the service is an agent or not. 

 

Agent or not:

Step 1. Use Web Request node with below settings.

Request type: GET

Endpoint: https://mycronicitsupport.freshservice.com/api/v2/requesters/{{ticket.requester.id}}

Step 2. Use the JSON Parser node and set the Web Request response body as Source.

Step 3. Use a Condition node and use the JSON Parser node to find “requester.is_agent” is “true”

 

Create the relationship:

Create 2 Web Request nodes after the “is_agent” condition.

If the requester is an agent, the web request node can be set as below

Request type: POST

Endpoint: https://mycompany.com/api/v2/relationships/bulk-create

Body: 

{
  "relationships": [
    {
      "relationship_type_id": 52000081231,
      "primary_id": {{ticket.requester.id}},
      "primary_type": "agent",
      "secondary_id": 13,
      "secondary_type": "asset"
    }
  ]
}

 

If the requester is not an agent, the Body would be same but you need to change the type to “requester” as below

Body: 

{
  "relationships": [
    {
      "relationship_type_id": 52000081231,
      "primary_id": {{ticket.requester.id}},
      "primary_type": "requester",
      "secondary_id": 13,
      "secondary_type": "asset"
    }
  ]
}

Note that the “relationship_type_id” is the actual id of the relationship you wish to create while the “secondary_id” is the display id of the asset, not the actual id. To get these id´s I played around with web request (GET) nodes and used “/api/v2/assets” and “/api/v2/relationship_types” as endpoints to find the correct ID´s.

I’ve attached screenshots of the workflow and the resulting relationship created


Forum|alt.badge.img+1

@maghed , 2.5 years later and I wanted to say thanks for documenting the solution above that we could stumble across. 

maghed wrote:

I solved this by using a series of the “Web Request” nodes in the workflow. 


 

We’re trying to implement something similar to make the “Used By” asset relationship update whenever the similar “Used By” asset assignment field is changed -- see separate post: 


I don’t have any testing yet to confirm, but we’re optimistic your solution will help us figure it out.