Typescript SDK Samples - Layouts Operations
Get Layouts
import * as ZOHOCRMSDK from "@zohocrm/typescript-sdk-2.1";
export class Layouts{
/**
* Get Layouts
* This method is used to get metadata about all the layouts of a module and print the response.
* @param moduleAPIName The API Name of the module to get layouts.
*/
public static async getLayouts(moduleAPIName: string) {
//example
//let moduleAPIName = "Leads";
//Get instance of LayoutsOperations Class that takes moduleAPIName as parameter
let layoutsOperations: ZOHOCRMSDK.Layouts.LayoutsOperations = new ZOHOCRMSDK.Layouts.LayoutsOperations(moduleAPIName);
//Call getLayouts method
let response: ZOHOCRMSDK.APIResponse<ZOHOCRMSDK.Layouts.ResponseHandler.MasterModel> = await layoutsOperations.getLayouts();
if (response != null) {
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
if ([204, 304].includes(response.getStatusCode())) {
console.log(response.getStatusCode() == 204 ? "No Content" : "Not Modified");
return;
}
//Get object from response
let responseObject: ZOHOCRMSDK.Layouts.ResponseHandler.MasterModel = response.getObject();
if (responseObject != null) {
//Check if expected ResponseWrapper instance is received.
if (responseObject instanceof ZOHOCRMSDK.Layouts.ResponseWrapper) {
//Get the array of obtained Layout instances
let layouts: ZOHOCRMSDK.Layouts.Layout[] = responseObject.getLayouts();
layouts.forEach(layout => {
if (layout.getCreatedTime() != null) {
//Get the CreatedTime of each Layout
console.log("Layout CreatedTime: " + layout.getCreatedTime().toString());
}
//Check if ConvertMapping is not null
if (layout.getConvertMapping() != null) {
//Get the ConvertMapping map
Array.from(layout.getConvertMapping().keys()).forEach(key => {
console.log(key + ": " + layout.getConvertMapping().get(key));
});
}
if (layout.getModifiedTime() != null) {
//Get the ModifiedTime of each Layout
console.log("Layout ModifiedTime: " + layout.getModifiedTime());
}
//Get the Visible of each Layout
console.log("Layout Visible: " + layout.getVisible().toString());
//Get the createdFor User instance of each Layout
let createdFor: ZOHOCRMSDK.Users.User = layout.getCreatedFor();
//Check if createdFor is not null
if (createdFor != null) {
//Get the Name of the createdFor User
console.log("Layout CreatedFor User-Name: " + createdFor.getName());
//Get the ID of the createdFor User
console.log("Layout CreatedFor User-ID: " + createdFor.getId());
//Get the Email of the createdFor User
console.log("Layout CreatedFor User-Email: " + createdFor.getEmail());
}
//Get the Name of each Layout
console.log("Layout Name: " + layout.getName());
//Get the modifiedBy User instance of each Layout
let modifiedBy: ZOHOCRMSDK.Users.User = layout.getModifiedBy();
//Check if modifiedBy is not null
if (modifiedBy != null) {
//Get the Name of the modifiedBy User
console.log("Layout ModifiedBy User-Name: " + modifiedBy.getName());
//Get the ID of the modifiedBy User
console.log("Layout ModifiedBy User-ID: " + modifiedBy.getId());
//Get the Email of the modifiedBy User
console.log("Layout ModifiedBy User-Email: " + modifiedBy.getEmail());
}
//Get the profiles of each Layout
let profiles: ZOHOCRMSDK.Profiles.Profile[] = layout.getProfiles();
//Check if profiles is not null
if (profiles != null) {
profiles.forEach(profile => {
//Get the Default of each Profile
console.log("Layout Profile Default: " + profile.getDefault());
//Get the Name of each Profile
console.log("Layout Profile Name: " + profile.getName());
//Get the ID of each Profile
console.log("Layout Profile ID: " + profile.getId());
});
}
//Get the ID of each Layout
console.log("Layout ID: " + layout.getId());
//Get the createdBy User instance of each Layout
let createdBy: ZOHOCRMSDK.Users.User = layout.getCreatedBy();
//Check if createdBy is not null
if (createdBy != null) {
//Get the Name of the createdBy User
console.log("Layout CreatedBy User-Name: " + createdBy.getName());
//Get the ID of the createdBy User
console.log("Layout CreatedBy User-ID: " + createdBy.getId());
//Get the Email of the createdBy User
console.log("Layout CreatedBy User-Email: " + createdBy.getEmail());
}
//Get the sections of each Layout
let sections: ZOHOCRMSDK.Layouts.Section[] = layout.getSections();
//Check if sections is not null
if (sections != null) {
sections.forEach(section => {
//Get the DisplayLabel of each Section
console.log("Layout Section DisplayLabel: " + section.getDisplayLabel());
//Get the SequenceNumber of each Section
console.log("Layout Section SequenceNumber: " + section.getSequenceNumber().toString());
//Get the Issubformsection of each Section
console.log("Layout Section Issubformsection: " + section.getIssubformsection().toString());
//Get the TabTraversal of each Section
console.log("Layout Section TabTraversal: " + section.getTabTraversal().toString());
//Get the APIName of each Section
console.log("Layout Section APIName: " + section.getAPIName());
//Get the ColumnCount of each Section
console.log("Layout Section ColumnCount: " + section.getColumnCount().toString());
//Get the Name of each Section
console.log("Layout Section Name: " + section.getName());
//Get the GeneratedType of each Section
console.log("Layout Section GeneratedType: " + section.getGeneratedType());
//Get the fields of each Section
let fields: ZOHOCRMSDK.Fields.Field[] = section.getFields();
//Check if fields is not null
if (fields != null) {
for (let field of fields) {
this.printField(field);
}
}
//Get the properties User instance of each Section
let properties: ZOHOCRMSDK.Layouts.Properties = section.getProperties();
//Check if properties is not null
if (properties != null) {
//Get the ReorderRows of each Properties
console.log("Layout Section Properties ReorderRows: " + properties.getReorderRows().toString());
//Get the tooltip User instance of the Properties
let tooltip: ZOHOCRMSDK.Fields.ToolTip = properties.getTooltip();
//Check if tooltip is not null
if (tooltip != null) {
//Get the Name of the ToolTip
console.log("Layout Section Properties ToolTip Name: " + tooltip.getName().toString());
//Get the Value of the ToolTip
console.log("Layout Section Properties ToolTip Value: " + tooltip.getValue().toString());
}
//Get the MaximumRows of each Properties
console.log("Layout Section Properties MaximumRows: " + properties.getMaximumRows().toString());
}
});
}
//Get the Status of each Layout
console.log("Layout Status: " + layout.getStatus());
});
}
//Check if the request returned an exception
else if (responseObject instanceof ZOHOCRMSDK.Layouts.APIException) {
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string, any> = responseObject.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}
Get a Layout
import * as ZOHOCRMSDK from "@zohocrm/typescript-sdk-2.1";
export class Layouts{
/**
* Get Layout
* This method is used to get metadata about a single layout of a module with layoutID and print the response.
* @param moduleAPIName The API Name of the layout's modules
* @param layoutId The ID of the layout to be obtained
*/
public static async getLayout(moduleAPIName: string, layoutId: bigint) {
//example
//let moduleAPIName = "Leads";
//let layoutId = 34770610091055n
//Get instance of LayoutsOperations Class that takes moduleAPIName as parameter
let layoutsOperations: ZOHOCRMSDK.Layouts.LayoutsOperations = new ZOHOCRMSDK.Layouts.LayoutsOperations(moduleAPIName);
//Call getLayout method
let response: ZOHOCRMSDK.APIResponse<ZOHOCRMSDK.Layouts.ResponseHandler.MasterModel> = await layoutsOperations.getLayout(layoutId);
if (response != null) {
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
if ([204, 304].includes(response.getStatusCode())) {
console.log(response.getStatusCode() == 204 ? "No Content" : "Not Modified");
return;
}
//Get object from response
let responseObject = response.getObject();
if (responseObject != null) {
//Check if expected ResponseWrapper instance is received.
if (responseObject instanceof ZOHOCRMSDK.Layouts.ResponseWrapper) {
let layouts: ZOHOCRMSDK.Layouts.Layout[] = responseObject.getLayouts();
layouts.forEach(layout => {
if (layout.getCreatedTime() != null) {
//Get the CreatedTime of each Layout
console.log("Layout CreatedTime: " + layout.getCreatedTime().toString());
}
//Check if ConvertMapping is not null
if (layout.getConvertMapping() != null) {
//Get the MultiModuleLookup map
Array.from(layout.getConvertMapping().keys()).forEach(key => {
console.log(key + ": " + layout.getConvertMapping().get(key));
});
}
if (layout.getModifiedTime() != null) {
//Get the ModifiedTime of each Layout
console.log("Layout ModifiedTime: " + layout.getModifiedTime());
}
//Get the Visible of each Layout
console.log("Layout Visible: " + layout.getVisible().toString());
//Get the createdFor User instance of each Layout
let createdFor: ZOHOCRMSDK.Users.User = layout.getCreatedFor();
//Check if createdFor is not null
if (createdFor != null) {
//Get the Name of the createdFor User
console.log("Layout CreatedFor User-Name: " + createdFor.getName());
//Get the ID of the createdFor User
console.log("Layout CreatedFor User-ID: " + createdFor.getId());
//Get the Email of the createdFor User
console.log("Layout CreatedFor User-Email: " + createdFor.getEmail());
}
//Get the Name of each Layout
console.log("Layout Name: " + layout.getName());
//Get the modifiedBy User instance of each Layout
let modifiedBy: ZOHOCRMSDK.Users.User = layout.getModifiedBy();
//Check if modifiedBy is not null
if (modifiedBy != null) {
//Get the Name of the modifiedBy User
console.log("Layout ModifiedBy User-Name: " + modifiedBy.getName());
//Get the ID of the modifiedBy User
console.log("Layout ModifiedBy User-ID: " + modifiedBy.getId());
//Get the Email of the modifiedBy User
console.log("Layout ModifiedBy User-Email: " + modifiedBy.getEmail());
}
//Get the profiles of each Layout
let profiles: ZOHOCRMSDK.Profiles.Profile[] = layout.getProfiles();
//Check if profiles is not null
if (profiles != null) {
profiles.forEach(profile => {
//Get the Default of each Profile
console.log("Layout Profile Default: " + profile.getDefault());
//Get the Name of each Profile
console.log("Layout Profile Name: " + profile.getName());
//Get the ID of each Profile
console.log("Layout Profile ID: " + profile.getId());
});
}
//Get the ID of each Layout
console.log("Layout ID: " + layout.getId());
//Get the createdBy User instance of each Layout
let createdBy: ZOHOCRMSDK.Users.User = layout.getCreatedBy();
//Check if createdBy is not null
if (createdBy != null) {
//Get the Name of the createdBy User
console.log("Layout CreatedBy User-Name: " + createdBy.getName());
//Get the ID of the createdBy User
console.log("Layout CreatedBy User-ID: " + createdBy.getId());
//Get the Email of the createdBy User
console.log("Layout CreatedBy User-Email: " + createdBy.getEmail());
}
//Get the sections of each Layout
let sections: ZOHOCRMSDK.Layouts.Section[] = layout.getSections();
//Check if sections is not null
if (sections != null) {
sections.forEach(section => {
//Get the DisplayLabel of each Section
console.log("Layout Section DisplayLabel: " + section.getDisplayLabel());
//Get the SequenceNumber of each Section
console.log("Layout Section SequenceNumber: " + section.getSequenceNumber().toString());
//Get the Issubformsection of each Section
console.log("Layout Section Issubformsection: " + section.getIssubformsection().toString());
//Get the TabTraversal of each Section
console.log("Layout Section TabTraversal: " + section.getTabTraversal().toString());
//Get the APIName of each Section
console.log("Layout Section APIName: " + section.getAPIName());
//Get the ColumnCount of each Section
console.log("Layout Section ColumnCount: " + section.getColumnCount().toString());
//Get the Name of each Section
console.log("Layout Section Name: " + section.getName());
//Get the GeneratedType of each Section
console.log("Layout Section GeneratedType: " + section.getGeneratedType());
//Get the fields of each Section
let fields: ZOHOCRMSDK.Fields.Field[] = section.getFields();
//Check if fields is not null
if (fields != null) {
for (let field of fields) {
this.printField(field);
}
}
//Get the properties instance of each Section
let properties: ZOHOCRMSDK.Layouts.Properties = section.getProperties();
//Check if properties is not null
if (properties != null) {
//Get the ReorderRows of each Properties
console.log("Layout Section Properties ReorderRows: " + properties.getReorderRows().toString());
//Get the tooltip User instance of the Properties
let tooltip: ZOHOCRMSDK.Fields.ToolTip = properties.getTooltip();
//Check if tooltip is not null
if (tooltip != null) {
//Get the Name of the ToolTip
console.log("Layout Section Properties ToolTip Name: " + tooltip.getName().toString());
//Get the Value of the ToolTip
console.log("Layout Section Properties ToolTip Value: " + tooltip.getValue().toString());
}
//Get the MaximumRows of each Properties
console.log("Layout Section Properties MaximumRows: " + properties.getMaximumRows().toString());
}
});
}
//Get the Status of each Layout
console.log("Layout Status: " + layout.getStatus());
});
}
//Check if the request returned an exception
else if (responseObject instanceof ZOHOCRMSDK.Layouts.APIException) {
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details: Map<string, any> = responseObject.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}