Client Script
Tue Jun 24 2025 09:21:45 GMT+0000 (Coordinated Universal Time)
Saved by @usman13
/**
* log("sample logging statement") --> can be used to print any data in the browser console.
* ZDK module can be used for customising the UI and other functionalities.
* return false to prevent <SAVE> action
**/
var account_name = ZDK.Page.getField('Account_Name').getValue();
console.log("Account name value: ", account_name);
var contactnamefield= ZDK.Page.getField("Contact_Name").getValue();
console.log("Value of Contact name Field is ", contactnamefield);
var Show_Number_of_Unit=ZDK.Page.getField("Show_Number_of_Unit");
console.log("Show_Number_of_Unit = ", Show_Number_of_Unit);
var Show_Number_of_Unit_Vaule=ZDK.Page.getField("Show_Number_of_Unit").getValue();
console.log("Show_Number_of_Unit_value = ", Show_Number_of_Unit_Vaule);
if (account_name != null)
{
console.log("Account Name is not Equal to Null");
var accountnameid = account_name['id'];
console.log("account name id: ", accountnameid);
var related_records = ZDK.Apps.CRM.Accounts.fetchRelatedRecords(accountnameid, "Contacts");
for (var i = 0; i < related_records.length; i++)
{
console.log("related_records [i]", related_records[i]);
//////////////////////
var contact_id = related_records[i].id;
var contact_tag = related_records[i];
console.log("contact_id new",contact_id);
console.log("Tags New", contact_tag.Tag);
var tags_info = contact_tag.Tag;
console.log("tag=========", tags_info);
var Tags = [
{name: "Bob", id: "32", occupation: "developer"},
{name: "ERPHUB POC", id: "17", occupation: "delinquent"},
{name: "Brad", id: "40", occupation: "yes"}
]
let matchedPOC = Tags.find(function (ele) {
console.log("contact_id new poc",contact_id);
return ele.name == "ERPHUB POC";
});
console.log("matched: ", matchedPOC);
// for (var i = 0; i < tags_info.length; i++)
// {
// console.log("tags_info",contact_tag.Tag);
// }
///////////////////////////
console.log("related_records[i].Primary_Contact", related_records[i].Primary_Contact);
if(related_records[i].Primary_Contact==true)
{
true_related_record = related_records[i];
console.log("true_related_record",true_related_record);
}
else
{
true_related_record=related_records[0];
console.log("true_related_record [0]",true_related_record);
}
}
console.log("true_related_record Email",true_related_record.Email);
console.log("true_related_record Full_Name",true_related_record.Full_Name);
console.log("true_related_record id",true_related_record.id);
var emailfield = ZDK.Page.getField('Email');
console.log("email field value: ",emailfield);
console.log("set email address");
//emailfield.setValue(true_related_record.Email);
var contactnamefield = ZDK.Page.getField("Contact_Name");
//contactnamefield.setValue({ "id": true_related_record.id, "name": true_related_record.Full_Name });
console.log("set contact name");
//console.log("id is :",true_related_record.id,"name is ",true_related_record.Full_Name);
var accounts = ZDK.Apps.CRM.Accounts.fetchById(accountnameid);
console.log("accounts: ", accounts);
var numofemployeesfield = ZDK.Page.getField("Number_of_Employees");
console.log("num of employees field: ",numofemployeesfield);
var foundingyearfield = ZDK.Page.getField("Founding_Year");
var lead_source = ZDK.Page.getField("Lead_Source");
lead_source.setValue(accounts.Lead_Source);
var websitee = ZDK.Page.getField("Website");
websitee.setValue(accounts.Website);
console.log("foundingyearfield", foundingyearfield);
if (accounts.Founding_Year == null)
{
console.log("if condition Founding_Year");
foundingyearfield.setValue(0);
}
else
{
console.log("else condition Founding_Year");
foundingyearfield.setValue(accounts.Founding_Year);
}
if (accounts.Number_of_Employees == null)
{
console.log("if condition Number_of_Employees",accounts.Number_of_Employees);
numofemployeesfield.setValue("-None-");
}
else
{
console.log("else condition Number_of_Employees",accounts.Number_of_Employees);
numofemployeesfield.setValue(accounts.Number_of_Employees);
}
var client_typefield = ZDK.Page.getField("Client_Type");
console.log("client_typefield = ", client_typefield);
if (accounts.Client_Type==null)
{
console.log("if condition client_typefield is null",accounts.Client_Type);
client_typefield.setValue("-None-");
}
else
{
console.log("else condition in Client_type",accounts.Client_Type);
client_typefield.setValue(accounts.Client_Type);
}
var industryfield = ZDK.Page.getField('Industry');
console.log("industryfield", industryfield);
if (accounts.Industry == null)
{
console.log("if condition Industry");
industryfield.setValue("-None-");
}
else
{
console.log("else condition Industry");
industryfield.setValue(accounts.Industry);
}
var serviceintrestedfield= ZDK.Page.getField("Services_Interested").getValue();
console.log("serviceintrestedfield",serviceintrestedfield);
if (serviceintrestedfield=="Property Management Solution")
{
console.log("True");
Show_Number_of_Unit.setValue(true);
}
else {
console.log("False");
Show_Number_of_Unit.setValue(false);
}
var client_tpye_value=ZDK.Page.getField("Client_Type").getValue();
console.log("client_tpye_value",client_tpye_value);
}
else
{
console.log("Account Name is Equal to Null");
var emailfield = ZDK.Page.getField('Email');
emailfield.setValue(null);
var contactnamefield= ZDK.Page.getField("Contact_Name");
contactnamefield.setValue(null);
var numofemployeesfield = ZDK.Page.getField("Number_of_Employees");
numofemployeesfield.setValue("-None-");
var foundingyearfield = ZDK.Page.getField("Founding_Year");
foundingyearfield.setValue(null);
var client_typefield = ZDK.Page.getField("Client_Type");
client_typefield.setValue("-None-");
var industryfield = ZDK.Page.getField('Industry');
industryfield.setValue("-None-");
}



Comments