JavaScript SDK Samples - Modules Operations
class Module
{
/**
* Get Modules
* This method is used to get metadata about all the modules and print the response.
*/
static async getModules() {
//Get instance of ModulesOperations Class
let modulesOperations = new ZCRM.Module.Operations();
//Get the instance of HeaderMap Class
let headerInstance = new HeaderMap();
//Add header to HeaderMap instance, if necessary
// await headerInstance.add(ZCRM.Module.Model.GetModulesHeader.IF_MODIFIED_SINCE, new Date("2020-07-13T12:12:12+05:30"));
//Call getModules method that takes headerInstance as parameters
let response = await modulesOperations.getModules(headerInstance);
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 ZCRM.Module.Model.ResponseWrapper) {
//Get the array of obtained Module instances
let modules = responseObject.getModules();
modules.forEach(module => {
//Get the Name of each Module
console.log("Module Name: " + module.getName());
//Get the GlobalSearchSupported of each Module
console.log("Module GlobalSearchSupported: " + module.getGlobalSearchSupported().toString());
//Get the Deletable of each Module
console.log("Module Deletable: " + module.getDeletable().toString());
//Get the Description of each Module
console.log("Module Description: " + module.getDescription());
//Get the Creatable of each Module
console.log("Module Creatable: " + module.getCreatable().toString());
//Get the InventoryTemplateSupported of each Module
console.log("Module InventoryTemplateSupported: " + module.getInventoryTemplateSupported().toString());
if (module.getModifiedTime() != null) {
//Get the ModifiedTime of each Module
console.log("Module ModifiedTime: " + module.getModifiedTime());
}
//Get the PluralLabel of each Module
console.log("Module PluralLabel: " + module.getPluralLabel());
//Get the PresenceSubMenu of each Module
console.log("Module PresenceSubMenu: " + module.getPresenceSubMenu().toString());
//Get the TriggersSupported of each Module
console.log("Module TriggersSupported: " + module.getTriggersSupported().toString());
//Get the Id of each Module
console.log("Module Id: " + module.getId().toString());
//Get the Visibility of each Module
console.log("Module Visibility: " + module.getVisibility().toString());
//Get the Convertable of each Module
console.log("Module Convertable: " + module.getConvertable().toString());
//Get the Editable of each Module
console.log("Module Editable: " + module.getEditable().toString());
//Get the EmailtemplateSupport of each Module
console.log("Module EmailtemplateSupport: " + module.getEmailtemplateSupport().toString());
//Get the list of Profile instance each Module
let profiles = module.getProfiles();
//Check if profiles is not null
if (profiles != null) {
profiles.forEach(profile => {
//Get the Name of each Profile
console.log("Module Profile Name: " + profile.getName());
//Get the Id of each Profile
console.log("Module Profile Id: " + profile.getId().toString());
});
}
//Get the FilterSupported of each Module
console.log("Module FilterSupported: " + module.getFilterSupported().toString());
//Get the ShowAsTab of each Module
console.log("Module ShowAsTab: " + module.getShowAsTab().toString());
//Get the WebLink of each Module
console.log("Module WebLink: " + module.getWebLink());
//Get the SequenceNumber of each Module
console.log("Module SequenceNumber: " + module.getSequenceNumber().toString());
//Get the SingularLabel of each Module
console.log("Module SingularLabel: " + module.getSingularLabel());
//Get the Viewable of each Module
console.log("Module Viewable: " + module.getViewable().toString());
//Get the APISupported of each Module
console.log("Module APISupported: " + module.getAPISupported().toString());
//Get the APIName of each Module
console.log("Module APIName: " + module.getAPIName());
//Get the QuickCreate of each Module
console.log("Module QuickCreate: " + module.getQuickCreate().toString());
//Get the modifiedBy User instance of each Module
let modifiedBy = module.getModifiedBy();
//Check if modifiedBy is not null
if (modifiedBy != null) {
//Get the name of the modifiedBy User
console.log("Module Modified By User-Name: " + modifiedBy.getName());
//Get the ID of the modifiedBy User
console.log("Module Modified By User-ID: " + modifiedBy.getId());
}
//Get the GeneratedType of each Module
console.log("Module GeneratedType: " + module.getGeneratedType().getValue());
//Get the FeedsRequired of each Module
console.log("Module FeedsRequired: " + module.getFeedsRequired().toString());
//Get the ScoringSupported of each Module
console.log("Module ScoringSupported: " + module.getScoringSupported().toString());
//Get the WebformSupported of each Module
console.log("Module WebformSupported: " + module.getWebformSupported().toString());
//Get the list of Argument instance each Module
let moduleArguments = module.getArguments();
//Check if arguments is not null
if (moduleArguments != null) {
moduleArguments.forEach(argument => {
//Get the Name of each Argument
console.log("Module Argument Name: " + argument.getName());
//Get the Value of each Argument
console.log("Module Argument Value: " + argument.getValue());
});
}
//Get the ModuleName of each Module
console.log("Module ModuleName: " + module.getModuleName());
//Get the BusinessCardFieldLimit of each Module
console.log("Module BusinessCardFieldLimit: " + module.getBusinessCardFieldLimit().toString());
//Get the parentModule Module instance of each Module
let parentModule = module.getParentModule();
//Check if arguments is not null
if (parentModule != null && parentModule.getAPIName() != null) {
//Get the Name of Parent Module
console.log("Module Parent Module Name: " + parentModule.getAPIName());
//Get the Value of Parent Module
console.log("Module Parent Module Id: " + parentModule.getId().toString());
}
});
}
//Check if the request returned an exception
else if (responseObject instanceof ZCRM.Module.Model.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 = 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());
}
}
}
}
}
class Module
{
/**
* Get Module
* This method is used to get metadata about single module with it's API Name and print the response.
* @param {String} moduleAPIName The API Name of the module to obtain metadata
*/
static async getModule(moduleAPIName) {
//example
//let moduleAPIName = "Leads";
//Get instance of ModulesOperations Class
let modulesOperations = new ZCRM.Module.Operations();
//Call getModule method that takes moduleAPIName as parameter
let response = await modulesOperations.getModule(moduleAPIName);
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 ZCRM.Module.Model.ResponseWrapper) {
//Get the array of obtained Module instances
let modules = responseObject.getModules();
modules.forEach(module => {
//Get the Name of each Module
console.log("Module Name: " + module.getName());
//Get the GlobalSearchSupported of each Module
console.log("Module GlobalSearchSupported: " + module.getGlobalSearchSupported().toString());
if (module.getKanbanView() != null) {
//Get the KanbanView of each Module
console.log("Module KanbanView: " + module.getKanbanView().toString());
}
//Get the Deletable of each Module
console.log("Module Deletable: " + module.getDeletable().toString());
//Get the Description of each Module
console.log("Module Description: " + module.getDescription());
//Get the Creatable of each Module
console.log("Module Creatable: " + module.getCreatable().toString());
if (module.getFilterStatus() != null) {
//Get the FilterStatus of each Module
console.log("Module FilterStatus: " + module.getFilterStatus().toString());
}
//Get the InventoryTemplateSupported of each Module
console.log("Module InventoryTemplateSupported: " + module.getInventoryTemplateSupported().toString());
if (module.getModifiedTime() != null) {
//Get the ModifiedTime of each Module
console.log("Module ModifiedTime: " + module.getModifiedTime());
}
//Get the PluralLabel of each Module
console.log("Module PluralLabel: " + module.getPluralLabel());
//Get the PresenceSubMenu of each Module
console.log("Module PresenceSubMenu: " + module.getPresenceSubMenu().toString());
//Get the TriggersSupported of each Module
console.log("Module TriggersSupported: " + module.getTriggersSupported().toString());
//Get the Id of each Module
console.log("Module Id: " + module.getId().toString());
//Get the RelatedListProperties instance of each Module
let relatedListProperties = module.getRelatedListProperties();
//Check if relatedListProperties is not null
if (relatedListProperties != null) {
//Get the SortBy of RelatedListProperties
console.log("Module RelatedListProperties SortBy: " + relatedListProperties.getSortBy());
//Get List of fields APIName
let fields = relatedListProperties.getFields();
//Check if fields is not null
if (fields != null) {
fields.forEach(fieldName => {
//Get the Field Name
console.log("Module RelatedListProperties Fields: " + fieldName);
});
}
//Get the SortOrder of RelatedListProperties
console.log("Module RelatedListProperties SortOrder: " + relatedListProperties.getSortOrder());
}
//Get List of properties field APIName
let properties = module.getProperties();
//Check if properties is not null
if (properties != null) {
properties.forEach(fieldName => {
//Get the Field Name
console.log("Module Properties Fields: " + fieldName);
});
}
//Get the PerPage of each Module
console.log("Module PerPage: " + module.getPerPage().toString());
//Get the Visibility of each Module
console.log("Module Visibility: " + module.getVisibility().toString());
//Get the Convertable of each Module
console.log("Module Convertable: " + module.getConvertable().toString());
//Get the Editable of each Module
console.log("Module Editable: " + module.getEditable().toString());
//Get the EmailtemplateSupport of each Module
console.log("Module EmailtemplateSupport: " + module.getEmailtemplateSupport().toString());
//Get the list of Profile instance each Module
let profiles = module.getProfiles();
//Check if profiles is not null
if (profiles != null) {
profiles.forEach(profile => {
//Get the Name of each Profile
console.log("Module Profile Name: " + profile.getName());
//Get the Id of each Profile
console.log("Module Profile Id: " + profile.getId().toString());
});
}
//Get the FilterSupported of each Module
console.log("Module FilterSupported: " + module.getFilterSupported().toString());
//Get the DisplayField of each Module
console.log("Module DisplayField: " + module.getDisplayField());
//Get List of SearchLayoutFields APIName
let searchLayoutFields = module.getSearchLayoutFields();
//Check if searchLayoutFields is not null
if (searchLayoutFields != null) {
searchLayoutFields.forEach(fieldName => {
//Get the Field Name
console.log("Module SearchLayoutFields Fields: " + fieldName);
});
}
if (module.getKanbanViewSupported() != null) {
//Get the KanbanViewSupported of each Module
console.log("Module KanbanViewSupported: " + module.getKanbanViewSupported().toString());
}
//Get the ShowAsTab of each Module
console.log("Module ShowAsTab: " + module.getShowAsTab().toString());
//Get the WebLink of each Module
console.log("Module WebLink: " + module.getWebLink());
//Get the SequenceNumber of each Module
console.log("Module SequenceNumber: " + module.getSequenceNumber().toString());
//Get the SingularLabel of each Module
console.log("Module SingularLabel: " + module.getSingularLabel());
//Get the Viewable of each Module
console.log("Module Viewable: " + module.getViewable().toString());
//Get the APISupported of each Module
console.log("Module APISupported: " + module.getAPISupported().toString());
//Get the APIName of each Module
console.log("Module APIName: " + module.getAPIName());
//Get the QuickCreate of each Module
console.log("Module QuickCreate: " + module.getQuickCreate().toString());
//Get the modifiedBy User instance of each Module
let modifiedBy = module.getModifiedBy();
//Check if modifiedBy is not null
if (modifiedBy != null) {
//Get the name of the modifiedBy User
console.log("Module Modified By User-Name: " + modifiedBy.getName());
//Get the ID of the modifiedBy User
console.log("Module Modified By User-ID: " + modifiedBy.getId());
}
//Get the GeneratedType of each Module
console.log("Module GeneratedType: " + module.getGeneratedType().getValue());
//Get the FeedsRequired of each Module
console.log("Module FeedsRequired: " + module.getFeedsRequired().toString());
//Get the ScoringSupported of each Module
console.log("Module ScoringSupported: " + module.getScoringSupported().toString());
//Get the WebformSupported of each Module
console.log("Module WebformSupported: " + module.getWebformSupported().toString());
//Get the list of Argument instance each Module
let moduleArguments = module.getArguments();
//Check if arguments is not null
if (moduleArguments != null) {
moduleArguments.forEach(argument => {
//Get the Name of each Argument
console.log("Module Argument Name: " + argument.getName());
//Get the Value of each Argument
console.log("Module Argument Value: " + argument.getValue());
});
}
//Get the ModuleName of each Module
console.log("Module ModuleName: " + module.getModuleName());
//Get the BusinessCardFieldLimit of each Module
console.log("Module BusinessCardFieldLimit: " + module.getBusinessCardFieldLimit().toString());
//Get the CustomView instance of each Module
let customView = module.getCustomView();
//Check if customView is not null
if (customView != null) {
this.printCustomView(customView);
}
//Get the parentModule Module instance of each Module
let parentModule = module.getParentModule();
//Check if parentModule is not null
if (parentModule != null && parentModule.getAPIName() != null) {
//Get the Name of Parent Module
console.log("Module Parent Module Name: " + parentModule.getAPIName());
//Get the Value of Parent Module
console.log("Module Parent Module Id: " + parentModule.getId().toString());
}
});
}
//Check if the request returned an exception
else if (responseObject instanceof ZCRM.Module.Model.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 = 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());
}
}
}
}
}
class Module
{
/**
* Update Module By APIName
* This method is used to update module details using module APIName and print the response.
* @param {String} moduleAPIName The API Name of the module to update
*/
static async updateModuleByAPIName(moduleAPIName) {
//example
//let moduleAPIName = "Leads";
//Get instance of ModulesOperations Class
let modulesOperations = new ZCRM.Module.Operations();
let modulesArray = [];
let profilesArray = [];
//Get instance of Profile Class
let profile = new ZCRM.Profile.Model.Profile();
//To set the Profile Id
profile.setId(34770610026014n);
//Add Profile instance to the array
profilesArray.push(profile);
//Get instance of Module Class
let module = new ZCRM.Module.Model.Module();
//Set the array to profiles in Module instance
module.setProfiles(profilesArray);
//Add the Module instance to array
modulesArray.push(module);
//Get instance of BodyWrapper Class which contains the request body
let request = new ZCRM.Module.Model.BodyWrapper();
//Set the array to modules in BodyWrapper instance
request.setModules(modulesArray);
//Call updateModuleByAPIName method that takes BodyWrapper instance and moduleAPIName as parameter
let response = await modulesOperations.updateModuleByAPIName(moduleAPIName, request);
if (response != null) {
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
//Get object from response
let responseObject = response.getObject();
if (responseObject != null) {
//Check if expected ActionWrapper instance is received
if (responseObject instanceof ZCRM.Module.Model.ActionWrapper) {
//Get the array of obtained ActionResponse instances
let actionResponses = responseObject.getModules();
actionResponses.forEach(actionResponse => {
//Check if the request is successful
if (actionResponse instanceof ZCRM.Module.Model.SuccessResponse) {
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details = actionResponse.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + actionResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if (actionResponse instanceof ZCRM.Module.Model.APIException) {
//Get the Status
console.log("Status: " + actionResponse.getStatus().getValue());
//Get the Code
console.log("Code: " + actionResponse.getCode().getValue());
console.log("Details");
//Get the details map
let details = actionResponse.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + actionResponse.getMessage().getValue());
}
});
}
//Check if the request returned an exception
else if (responseObject instanceof ZCRM.Module.Model.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 = 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());
}
}
}
}
}