Dynamic Field Handler

Dynamic Field Handler

The dynamic field change handler is associated with the dynamic-select field type. This handler is triggered to populate the drop-down menu items for the field based on the user input. The list of menu items to be populated in the drop-down is configured in this handler as a comma separated value list and the search trigger works based on the following criteria:

  • starts-with 
  • contains

Search results are populated based on the starts-with criteria followed by items that match with the contains criteria. 

Note:

For optimum results configure dynamic_select field only when the search results are more than 100. Incase of results lesser than 100, use the select field. 

The list of attributes that are passed when this handler is triggered are given below

Attribute NameTypeDescription
targetmapThe target map contains the users' search query and the field for which the search was triggered. 
formmapForm contains all the values and inputs of all the search fields in the form.
usermapThe user map contains details about the user who is interacting with the form. 
chatmapThe chat map contains details about the chat where the form is displayed as a response.

Target Map Syntax


{
"query": "",
"name": ""
}

Example: Update a lead's status in CRM

Consider a /crm command that lets you search for a lead and update the lead status within your Cliq interface. 

  1. Once you execute this command, a lead status form is displayed as a response.
  2. You can then search for the lead and choose the lead status.  
  3. On choosing these options, the form function submit handler is executed to update the lead record in your CRM. 

/crm Command Execution Handler



response = Map();
inputs = list();
getLeads = invokeUrl
[
url : "https://www.zohoapis.com/crm/v2/leads"
type : GET
connection : ENTER YOUR CONNECTION NAME
];
info getLeads;
leads = getLeads.get("data");
leadlist = List();
count = 0;
for each  lead in leads
{
	leadName = lead.get("Full_Name");
	leadId = lead.get("id");
	Lead = {"label":leadName,"value":leadId};
    
if (count < 10 )
{
	leadlist.add(Lead);
}
count = count +1;
}
inputs.add({"type":"dynamic_select","trigger_on_change":true,"name":"leadsearch","label":"Search Lead","hint":"Search the lead to be updated","placeholder":"ABC Corp","mandatory":true,"value":"ABCCorp","options":leadlist});
form = {"type":"form","title":"Update lead status","hint":"Search and update a lead","name":"lead","version":1,"button_label":"Update","action":{"type":"invoke.function","name":"leadupdate"},"trigger_on_cancel":true,"inputs":inputs};
return form;

leadupdate Form Function Dynamic Field Handler



info target;
searchValue = target.get("query");
getLeads = invokeurl
[
	url :"https://www.zohoapis.com/crm/v2/leads"
	type :GET
	connection:"ENTER YOUR CONNECTION NAME"
];
info getLeads;
leads = getLeads.get("data");
leadlist = list();
for each  lead in leads
{
	if(lead.containsIgnoreCase(searchValue))
	{
		leadName = lead.get("Full_Name");
		leadId = lead.get("id");
		Lead = {"label":leadName,"value":leadId};
		leadlist.add(Lead);
	}
}
return {"options":leadlist};

leadupdate Form Function Change Handler



targetName = target.get("name");
info targetName;
inputValues = form.get("values");
info inputValues;
actions = list();
leadStatus = {{"label":"Attempted to Contact","value":"attempt"},{"label":"Contact in Future","value":"future"},{"label":"Contacted","value":"contacted"},{"label":"Junk Lead","value":"junklead"},{"label":"Lost Lead","value":"lostlead"},{"label":"Pre-Qualified","value":"prequalified"},{"label":"Qualified","value":"Qualified"}};
if(targetName.containsIgnoreCase("leadsearch"))
{
	fieldValue = inputValues.get("leadsearch").get("value");
	getLeadInfo = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v2/leads/" + fieldValue
		type :GET
		connection:"ENTER YOUR CONNECTION NAME"
	];
	currentStatus = getLeadInfo.get("data").toList().get(0).toMap().get("Lead_Status");
	info currentStatus;
	leadStatuslist = List();
	for each  statitem in leadStatus
	{
		label = statitem.get("label");
		mapvalue = statitem.get("value");
		if(!label.equalsIgnoreCase(currentStatus))
		{
			leadStatusMap = {"label":label,"value":mapvalue};
			leadStatuslist.add(leadStatusMap);
		}
	}
	info leadStatusMap;
	info leadStatuslist;
	actions.add({"type":"add_after","name":"leadsearch","input":{"type":"select","name":"leadstatus","label":"Lead Status","hint":"Update your lead status","placeholder":"Contacted","mandatory":true,"options":leadStatuslist}});
}
return {"type":"form_modification","actions":actions};

leadupdate Form Function Submit Handler




response = Map();
leadid = form.get("values").get("leadsearch").get("value");
leadstatus = form.get("values").get("leadstatus").get("label");
info leadstatus;
dataMap = {
    "data": [
      {
        "Lead_Status": leadstatus
      }
    ]
};

updateLeads = invokeurl
[
	url : "https://www.zohoapis.com/crm/v2/leads/" + leadid
	type : PUT
	parameters: dataMap.toString()
	connection:"ENTER YOUR CONNECTION NAME"
];
info updateLeads;
if (updateLeads.get("data").toMap().get("code").equalsIgnoreCase("SUCCESS"))
{
response = {"text":"Your lead status has been updated to "+leadstatus +" :fireworks: "};
}
else 
{
response = {"text":"Unable to update lead status. Please try again later!"};
}
return response;

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohocliq.com