JSON Set Var Actions - Select Agents
Now we deal with the case when the customer does click on the URL in the email and triggers the "Customer Updated" event in Wait For Clickthrough element. What we do is we search for an agent that matches this criteria: He specializes in the promotional offer and he is licensed in the state where the customer resides.
We create a child element to Wait For Clickthrough element with these Set Var actions.
This is our code:
cus_areacode = areacode(__VG__CUSTOMER__.work_phone)
cus_state = ac_state(cus_areacode)
agent_criteria.logica.op='and'
agent_criteria.eq.Specialty=offer
agent_criteria.like.Licensed_State=cus_state
agents=searchagent(agent_criteria)
In the first two lines of code, we use the built-in functions areacode and ac_state to find the area code from the customer's workphone and find the state in which the area code resides in. That is the simple part. Our next step, we build the agent_criteria json object which we will use to search for agents that match that criteria. We first use the "eq" method, which is contains name value pairs that results in the name = value clause in the SQL where clause. So we're looking for an agent with the speciality in the promotional offer. Then we use the method "like" which produces name like '%value%'' in SQL. Now we have the logical operator 'and' to finish the criteria. The agents that match this criteria are agents that specialize in the promotional offer and are licensed in the state where the customer resides.
To search for all agents that match this criteria, we use a built-in function called searchagent. This function returns all rows of agents that match a given criteria in json format. So, agents = searchagent(agent_criteria) will give us all agents that match the criteria that we just built in json format.