ZOHO.CRM.META.getFields(config) |
Name | Type | Description |
Entity | String | SysRefName of the module. |
Util={}; var EntityId; var EntityName; var temp; var leadstatusdata; var leadids; var leadid; var leadname; var leaddata; var leadsourcename; //Subscribe to the EmbeddedApp onPageLoad event before initializing the widget ZOHO.embeddedApp.on("PageLoad",function(data) { EntityId=data.EntityId[0]; EntityName=data.Entity; console.log(EntityId); console.log(EntityName); //Looping through the selected lead records fetched from pageload for (l=0;l<EntityIds.length;l++) { //Fetching the complete details of the selected leads by passing their IDs ZOHO.CRM.API.getRecord({Entity:"Leads",RecordID:data.EntityId[l]}) .then(function(datas){ console.log(datas) leaddata=datas.data[0]; //Retrieving the names of the leads from the details fetched and populating them to a multi-select list var leadsids = document.getElementById("leadsids"); var option = document.createElement("OPTION"); leadid=leaddata.id; leadname=leaddata.Full_Name; option.innerHTML = leadname; option.value = leadid; leadsids.appendChild(option); }) } //Using the META getFields SDK to fetch the metadata of all the fields in the lead module ZOHO.CRM.META.getFields({"Entity":"Leads"}).then(function(data){ console.log(data); leadmetadata=data; leadmetadatarec=leadmetadata.fields; length=leadmetadata.fields.length; //Looping through all the fields metadata for(i=0;i<leadmetadatarec.length;i++) { if(leadmetadata.fields[i].api_name=="Lead_Status") { leadstatusdata=leadmetadata.fields[i].pick_list_values; console.log(leadstatusdata); leadmetadata1=leadstatusdata; length1=leadmetadata1.length; /*Looping through all the picklist values and appending the Lead status picklist values retrieved into the leadstatuses list*/ for (j=0;j<leadmetadata1.length;j++) { console.log(leadmetadata1[j].display_value); leadstatusid=leadmetadata1[j].id; leadstatusname=leadmetadata1[j].display_value; leadstatuses = document.getElementById("leadstatuses"); option = document.createElement("OPTION"); option.innerHTML = leadstatusname; option.value = leadstatusid; leadstatuses.appendChild(option); } } } }); // Updating the selected lead status to the selected lead Util.update=function() { //The leads chosen from the multi-select list are pushed to an array var selected = []; for (var option of document.getElementById('leadsids').options) { if (option.selected) { selected.push(option.value); } } //Looping through the leads chosen from the multi-select list for (m=0;m<selected.length;m++) { //Constructing the parameters to pass to the update api var config={ Entity:"Leads", APIData:{ "id":selected[m], "Lead_Status": document.getElementById("leadstatuses").value }, Trigger:[] } //Updating the chosen leads with the selected lead status value ZOHO.CRM.API.updateRecord(config) .then(function(data){ console.log(data) }) } } }) |
Writer is a powerful online word processor, designed for collaborative work.