ZDK Samples

Record Operations (REST API)
Create a Single Record

var lead = new ZDK.Apps.CRM.Leads();
lead.Last_Name = "dot sdK";
var response = lead.create();
log(response);
 
Update a Specific Record

var lead = ZDK.Apps.CRM.Leads.fetchById("4312588000000381015");
lead.Last_Name = "updated Name"
var response = lead.update();
log(response);
 
Delete a Specific Record

var lead = ZDK.Apps.CRM.Leads.fetchById("4312588000000381015")
var response = lead.remove();
log(response);
 
Create Multiple Records

var leads = new Array();
var lead1 = new ZDK.Apps.CRM.Leads();
lead1.Last_Name = "first lead";
leads.push(lead1);
var lead2 = new ZDK.Apps.CRM.Leads();
lead2.Last_Name = "second lead";
leads.push(lead2);
var response = ZDK.Apps.CRM.Leads.create(leads);
log(response);
 
Get Records

var leads = ZDK.Apps.CRM.Leads.fetch()
for(var i=0; i<leads.length; i++) {
  log(leads[i].Last_Name);
}
 
Get Records Using Page Number

var leads = ZDK.Apps.CRM.Leads.fetch(1);
for(var i=0; i<leads.length; i++) {
log(leads[i].Last_Name);
}
 
Filter Records Using Parameters

var leads = ZDK.Apps.CRM.Leads.fetch(1, 20, "Last_Name", "desc");
for(var i=0; i<leads.length; i++) {
log(leads[i].Last_Name);
}
 
Update Multiple Records

var leadsArray = new Array();
var lead1 = ZDK.Apps.CRM.Leads.fetchById("423383000005261048");
lead1.Last_Name = "Updated Name";
leadsArray.push(lead1);
var lead2 = ZDK.Apps.CRM.Leads.fetchById("423383000005267521");
lead2.Last_Name = "Updated Name2";
leadsArray.push(lead2);
var response = ZDK.Apps.CRM.Leads.update(leadsArray);
log(response[0].status);
 
Delete Multiple Records

var idsArray = new Array();
idsArray.push("4312588000000381013");
var response = ZDK.Apps.CRM.Leads.deleteByIds(idsArray);
log(response);
 
Add Picklist Field Value

var lead = new ZDK.Apps.CRM.Leads();
lead.Last_Name = "picklist test";
lead.Lead_Status = ZDK.Apps.CRM.Leads.Models.Lead_StatusPicklist.CONTACTED;
var response = lead.create();
log(response);
 
Add Multi-select picklist Field Value

var lead = new ZDK.Apps.CRM.Leads();
lead.Last_Name = "test";
var multi = new Array();
multi.push("Option 1");
multi.push("Option 2");
lead.Mutli_Select_1 = multi;
var response = lead.create()
log(response);
 
Add Lookup Field Value

var lead = ZDK.Apps.CRM.Leads.fetchById("4312588000000381015");
var user = lead.Created_By();
log(user.state);
 
Add New Record as Lookup Field Value

var account = new ZDK.Apps.CRM.Accounts();
account.Account_Name = "test";
var parent_account = ZDK.Apps.CRM.Accounts.fetchById("2000000065057");
account.Parent_Account(parent_account);
account.create();
 
Add Multi-select Lookup Field Value

var multi = new ZDK.Apps.CRM.LinkingModule3();
var lead = ZDK.Apps.CRM.Leads.fetchById("2000000074021");
multi.lead(lead);
var contact =  ZDK.Apps.CRM.Contacts.fetchById("2000000065057");
multi.Alternate_Contacts(contact);
var response = multi.create();
log(response);
 
Add Lookup Field Value Based on LookupID

var account = new ZDK.Apps.CRM.Accounts();
account.Account_Name = "test";
account.Parent_Account_Lookup_Id = "2000000065057";
account.create();
 
Create Subforms

var lead = new ZDK.Apps.CRM.Leads();
lead.Last_Name = "name";
var subform = new ZDK.Apps.CRM.Subform_1();
subform.singleLine1 = "single line";
var subforms = new Array();
subforms.push(subform);
lead.subform1 = subforms;
var response = lead.create();
log(response);
 
Read Subforms

var subforms = ZDK.Apps.CRM.Subform_1.fetch();
log(subforms);
 
Convert Leads

var convertLead = new ZDK.Apps.CRM.Leads.Models.ConvertLeads();
convertLead.Accounts = "735220000004375005";
convertLead.Deals = {
                "Pipeline"
  : ZDK.Apps.CRM.Deals.Models.PipelinePicklist.STANDARDSTANDARD,
                "Deal_Name": "Robert",
                "Closing_Date": "2020-11-20",
                "Stage": "Closed Won",
                "Amount": 56.6;
};

var response = ZDK.Apps.CRM.Leads.convert(convertLead, "735220000003635975");
 
Add Values to Special Fields such as Line_Items, Pricing_Model, and Participants

var invoice = new ZDK.Apps.CRM.Invoices();
invoice.Subject = "testing2";
var account = ZDK.Apps.CRM.Accounts.fetchById("2000000136022");
invoice.Account_Name(account);
var line_item = new ZDK.Apps.CRM.Invoices.Models.Line_Items();
var product = ZDK.Apps.CRM.Products.fetchById("2000000136027");
line_item.product(product);
line_item.quantity=3.0;
var line_items = new Array();
line_items.push(line_item);
invoice.Product_Details=line_items;

var response = invoice.create();
log(response);
 
Create PriceBooks

var book = new ZDK.Apps.CRM.Price_Books();
book.Price_Book_Name = "test";
book.Pricing_Model = ZDK.Apps.CRM.Price_Books.Models.Pricing_ModelPicklist.FLAT;
var pricing_detail = new ZDK.Apps.CRM.Price_Books.Models.Pricing_Details();
pricing_detail.from_range = 10;
pricing_detail.to_range = 100;
pricing_detail.discount = 5;
var pricing_detail2 = new ZDK.Apps.CRM.Price_Books.Models.Pricing_Details();
pricing_detail2.from_range = 1000;
pricing_detail2.to_range = 2000;
pricing_detail2.discount = 10;
var details = new Array();
details.push(pricing_detail);
details.push(pricing_detail2);
book.Pricing_Details = details;
var response = book.create();
log(response);
 
Add Participants to Events

var event = new ZDK.Apps.CRM.Events();
event.Event_Title = "testing";
event.Start_DateTime = "2020-10-22T21:00:00+05:45";
event.End_DateTime = "2020-10-24T21:00:00+06:45";
event.Description = "test";
event.Currency = "USD";
var participant = new ZDK.Apps.CRM.Events.Models.Participants();
participant.participant= "423383000004997180";
participant.type= "lead";
var participants = new Array();
participants.push(participant);
event.Participants = participants;
event.Tag = [ {
'id'
  : "735220000001193166";
}

]
var response = event.create();
log(response);
 
Function Operations
Trigger Function

var response = ZDK.Apps.CRM.Functions.execute("dealtoquote2")
log(response);
 
Trigger Function With Parameters

//parameters is of json type - {"amount": 100, "name": "test"}
var response = ZDK.Apps.CRM.Functions.execute("dealtoquote2", parameters);
log(response);
 
Connection Operations
Invoke Connections

//headers and parameters are json, if they are empty need to pass empty json {}
var response = ZDK.Apps.CRM.Connections.invoke("mailchimp4", "http://mailchimp.api/sample_api",  "POST", 1, parameters, headers);
 log(response);