// Get selected Sales Offer
var salesOffer = ZDK.Page.getField("Sales_Offer").getValue();
if (salesOffer == null) {
ZDK.Page.getField("Project_Name").setValue(null);
ZDK.Page.getField("Unit").setValue(null);
ZDK.Page.getField("Office_Location").setValue("");
return;
}
// Fetch Sales Offer (Quote) details
var quote = ZDK.Apps.CRM.Quotes.fetchById(salesOffer.id);
// ---------------- Project ----------------
var project = null;
var projectID = quote._Projects.id;
var projectName = quote._Projects.name;
// var = proj = quote.Project;
var proj = ZDK.Page.getField('Project_Name');
proj.setValue({
id: projectID,
name: projectName
});
if (quote.Projects != null) {
projectID = quote.Projects;
project = {
id: quote._Projects.id
};
}
var projectID = quote._Unit_Name.id;
var projectName = quote._Unit_Name.name;
var unit = ZDK.Page.getField('Unit');
unit.setValue({
id: projectID,
name: projectName
});
console.log(unit);
console.log(project);
// ---------------- Office Location ----------------
var officeLocation = "";
if (quote.Office_Location != null) {
officeLocation = quote.Office_Location;
}
ZDK.Page.getField("Office_Location").setValue(officeLocation);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter