Just helping the community by sharing a custom script that we implement. Always open to other ways to achieve this more efficiently.
Objective: I have different types of customers (I,E Vendor, Reseller, End-User),
- I want to record what type of customer they are when the customer logs a ticket.
- Store this data field against the Contact record
- Show this record on the ticket without having to have the agent open up the contact record
- Force the agent to update the Customer type field before allowing them to close the ticket
- If the customer logs any future tickets, those tickets will show the customer's type
Challenge: We can create custom fields on a ticket level and have them as required fields. But this data set belongs to the Contact record and not the Ticket record
Solution:
Part 1, Create the custom fields in the Contact Module
- Go to Customisation > Layouts and fields > Contacts
- Create a new field called Contact Type
- Note the API Name. In my case, it was called cf_contact_type
- I also set this to be a required field if we create the customer contact directly
Contact Module
Part 2, Create the custom fields in the Ticket Module- Go to Customisation > Layouts and fields > Tickets
- Create a new field called Contact Type
- Note the API Name. In my case, it was called cf_contact_type
- I also set this to be a required field if we create the ticket directly
Ticket Module
We now have a drop-down list called Contact Type in both Tickets and Contacts.
But we need to keep them in sync. We do this in a Workflow
Part 3, Create a workflow to update the Contact Type in the Contacts module when the Contact Type in the Ticket Module is updated.
Create a new Workflow in Automation > Workflows
- Module: Tickets
- Rule Name: 1.A Ticket to contact module sync for Contact Type
- Description: Updating the contact type on a ticket record will update the person record
- Execute on: Field Update: Contact Type (This is the new Custom field you created)
- Criteria: N/A
- Action: Custom Function: Create a new and give it a name (Ticket to Contact sync)
Paste in the following code and substitute with your OrgId and DeskURL
substitute the contactCfApiName and ticketCfApiName if you changed it above
- OrgId = xxxxxxxxxx;
- deskUrl = "https://xxxxxxxxxx.com";
- contactCfApiName = "cf_contact_type";
- ticketCfApiName = "cf_contact_type";
- connection = "zohodesk";
- updateContact = invokeurl
- [
- url :deskUrl + "/api/v1/contacts/" + contactId
- type :PATCH
- parameters:{"cf":{contactCfApiName:ticketCfValue}} + ""
- connection:connection
- ];
- info updateContact;
1.A Function Click on Edit Arguments and set the following Argument Names to these values
- contactId > Contact Id
- ticketId > Ticket Id
- ticketCfValue > Contact Type
- contactCfValue > Contact Type
Arguments We now are updating the Contact Type in the Contacts module when the Contact Type in the Ticket Module is updated.
But we want to have any new tickets created from that customer pull in the Contact Type from the Contact Module into any new Ticket we create
Part 4, Create a workflow so that any new ticket created will auto-populate the Contact Type in the Ticket module from the Contact Module
Create a new Workflow in Automation > Workflows
- Module: Tickets
- Rule Name: 1.B Apply contact type value for all new tickets
- Description: New ticket comes in, check person record if "customer type" is set and then copy it to the ticket
- Execute on: Create
- Criteria: N/A
- Action: Custom Function: Create a new and give it a name (
Apply contact type value for all new tickets
)
1.B Workflow Paste in the following code and substitute with your OrgId and DeskURL
substitute the contactCfApiName and ticketCfApiName if you changed it above
- OrgId = xxxxxxxxxx;
- deskUrl = "https://xxxxxxxxxx.com";
- contactCfApiName = "cf_contact_type";
- ticketCfApiName = "cf_contact_type";
- connection = "zohodesk";
- if(contactCfValue != null && contactCfValue != "")
- {
- updateTicket = invokeurl
- [
- url :deskUrl + "/api/v1/tickets/" + ticketId
- type :PATCH
- parameters:{"cf":{ticketCfApiName:contactCfValue}} + ""
- headers:{"featureFlags":"skipAutomations"}
- connection:connection
- ];
- info updateTicket;
- }
1.B Function Click on Edit Arguments and set the following Argument Names to these values
- contactId > Contact Id
- ticketId > Ticket Id
- ticketCfValue > Contact Type
- contactCfValue > Contact Type
Arguements End result
When a customer logs a ticket, it will first look at their contact Record and see if the customer field Contact Type is set. If it is it will copy that to the Ticket record and display it.
If it is not set, making a change in the Ticket record will update the Contact Record
If you want to force your agents to fill in this field before they close the ticket. You can setup a Blueprint that during the transition Contact Type must be set
It looks like this