Form Submit Handler

Form Action on Submission

On the submission of a form, the default action is considered for the Submit button. If the cancel button action is not handled in the function code, all the input values will be cancelled by default and the form will not return any response. 

Workflow of the form function

  1. Create a form for a specific task.
  2. Create a form function and associate the function with concerned form. 
  3. On form submission, the input values received in the function can be used to perform the intended action. Let us take a look at the example given below. 

Example: Add Note in Zoho CRM

For example let us consider a message action, Add note—to add a message as a note to a lead in Zoho CRM. On performing the message action, a form is displayed with the message content as the default value. The user can choose to keep the value as is or edit it. The dropdown menu brings the list of leads from Zoho CRM for the user to choose from. On clicking submit, the form function is invoked to add the message as a note to the selected lead.

Add Note Message Action Code


text = message.get("text").replaceAll("","");
response = Map();
inputs = list();
getAllLeads = invokeurl
[
	url :"https://www.zohoapis.com/crm/v2/leads"
	type :GET
	connection: ENTER YOUR CONNECTION NAME
];
leads = getAllLeads.get("data");
leadlist = List();
i = 0;
for each  lead in leads
{
	if(i == 10)
	{
		break;
	}
	leadName = lead.get("Full_Name");
	leadId = lead.get("id");
	Lead = {"label":leadName,"value":leadId};
	leadlist.add(Lead);
	i = i + 1;
}
inputs.add({"type":"textarea","name":"note","label":"Note","hint":"Add a note to a lead in CRM","placeholder":"Demo scheduled with Tech team","mandatory":true,"value":text});
inputs.add({"type":"select","name":"lead","label":"Leads","hint":"Pick a lead","placeholder":"Pick a lead","mandatory":true,"value":"lead","options":leadlist});
return {"type":"form","title":"Add note","hint":"Add a note to a lead in CRM","name":"ID","version":1,"button_label":"Add Note","action":{"type":"invoke.function","name":"notes"},"inputs":inputs};

 

Notes Form Function Submit Handler Code



info form;
note = form.get("values").get("note");
id = form.get("values").get("lead").get("value");
response = Map();
notesmap = Map();
notesmap.put("Note_Title","Note from Cliq");
notesmap.put("Note_Content",note);
notesmap.put("Parent_Id",id);
notesmap.put("se_module","Leads");
noteslist = List();
noteslist.add(notesmap);
map = Map();
map.put("data",noteslist);
response = invokeurl
[
	url :"https://www.zohoapis.com/crm/v2/leads/" + id + "/Notes"
	type :POST
	parameters:map.toString()
	connection:"ENTER YOUR CONNECTION NAME"
];
info response;
if(response.get("data").toMap().containValue("SUCCESS"))
{
response = {"text":"Notes added successfully. \n [View Lead](https://crm.zoho.com/crm/tab/Leads/"+id+")"};
}
else if(response.get("code") == "INVALID_DATA")
{
	response = {"text":"Failed to upload notes. Please try again later"};
}
else
{
	response = {"text":"Failed to upload notes. 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