Node JS SDK Samples - Share Records Operations
const {ShareRecordsOperations, GetSharedRecordDetailsParam} = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/share_records_operations");
const ParameterMap = require("@zohocrm/nodejs-sdk-2.0/routes/parameter_map").ParameterMap;
const ResponseWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/response_wrapper").ResponseWrapper;
const BodyWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/body_wrapper").BodyWrapper;
const ActionWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/action_wrapper").ActionWrapper;
const DeleteActionWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/delete_action_wrapper").DeleteActionWrapper;
const SuccessResponse = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/success_response").SuccessResponse;
const APIException = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/api_exception").APIException;
const ZCRMShareRecord = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/share_record").ShareRecord;
const ZCRMUser = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/users/user").User;
class ShareRecord{
/**
* Share Record
* This method is used to share the record and print the response.
* @param {String} moduleAPIName The API Name of the module to share record.
* @param {BigInt} recordId The ID of the record to be shared
*/
static async shareRecord(moduleAPIName, recordId){
//example
//let moduleAPIName = "Contacts";
// let recordId = 3409643000002112011n;
//Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
let sharedRecordsOperations = new ShareRecordsOperations(recordId, moduleAPIName);
//Get instance of BodyWrapper Class that will contain the request body
let request = new BodyWrapper();
//Array to hold ShareRecord instances
let shareRecordArray = [];
//Get instance of ShareRecord Class
let shareRecord = new ZCRMShareRecord();
//Set boolean value to share related records
shareRecord.setShareRelatedRecords(false);
//Set the permission. Possible values - full_access, read_only, read_write
shareRecord.setPermission("read_write");
//Get instance of User Class
let user = new ZCRMUser();
//Set User ID
user.setId(3409643000000302031n);
//Set the User instance to user
shareRecord.setUser(user);
//Add the instance to array
shareRecordArray.push(shareRecord);
//Set the array to share of BodyWrapper instance
request.setShare(shareRecordArray);
//Call shareRecord method that takes BodyWrapper instance as parameter
let response = await sharedRecordsOperations.shareRecord(request);
if(response != null){
//Get the status code from response
console.log("Status Code: " + response.statusCode);
//Get object from response
let responseObject = response.object;
if(responseObject != null){
//Check if expected ActionWrapper instance is received
if(responseObject instanceof ActionWrapper){
//Get the array of obtained ActionResponse instances
let actionResponses = responseObject.getShare();
actionResponses.forEach(actionResponse => {
//Check if the request is successful
if(actionResponse instanceof 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 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 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());
}
}
}
}
}
module.exports = {ShareRecord}
const {ShareRecordsOperations, GetSharedRecordDetailsParam} = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/share_records_operations");
const ParameterMap = require("@zohocrm/nodejs-sdk-2.0/routes/parameter_map").ParameterMap;
const ResponseWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/response_wrapper").ResponseWrapper;
const BodyWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/body_wrapper").BodyWrapper;
const ActionWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/action_wrapper").ActionWrapper;
const DeleteActionWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/delete_action_wrapper").DeleteActionWrapper;
const SuccessResponse = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/success_response").SuccessResponse;
const APIException = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/api_exception").APIException;
const ZCRMShareRecord = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/share_record").ShareRecord;
const ZCRMUser = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/users/user").User;
class ShareRecord{
/**
* Update Share Permissions
* This method is used to update the sharing permissions of a record granted to users as Read-Write, Read-only, or grant full access.
* @param {String} moduleAPIName The API Name of the module to update share permissions.
* @param {BigInt} recordId The ID of the record
*/
static async updateSharePermissions(moduleAPIName, recordId){
//example
//let moduleAPIName = "Contacts";
// let recordId = 3409643000002112011n;
//Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
let sharedRecordsOperations = new ShareRecordsOperations(recordId, moduleAPIName);
//Get instance of BodyWrapper Class that will contain the request body
let request = new BodyWrapper();
//Array to hold ShareRecord instances
let shareRecordArray = [];
//Get instance of ShareRecord
let shareRecord = new ZCRMShareRecord();
//Set the permission
shareRecord.setPermission("full_access");
//Set the boolean value to share related records
shareRecord.setShareRelatedRecords(true);
//Get instance of User Class
let user = new ZCRMUser();
//Set ID to the User
user.setId(3409643000000302031n);
//Set user instance to user in ShareRecord instance
shareRecord.setUser(user);
//Add the instance to array
shareRecordArray.push(shareRecord);
//Set the array to share in BodyWrapper
request.setShare(shareRecordArray);
//Call updateSharePermissions method that takes BodyWrapper instance as parameter
let response = await sharedRecordsOperations.updateSharePermissions(request);
if(response != null){
//Get the status code from response
console.log("Status Code: " + response.statusCode);
//Get object from response
let responseObject = response.object;
if(responseObject != null){
//Check if expected ActionWrapper instance is received
if(responseObject instanceof ActionWrapper){
//Get the array of obtained ActionResponse instances
let actionResponses = responseObject.getShare();
actionResponses.forEach(actionResponse => {
//Check if the request is successful
if(actionResponse instanceof 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 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 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());
}
}
}
}
}
module.exports = {ShareRecord}
const {ShareRecordsOperations, GetSharedRecordDetailsParam} = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/share_records_operations");
const ParameterMap = require("@zohocrm/nodejs-sdk-2.0/routes/parameter_map").ParameterMap;
const ResponseWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/response_wrapper").ResponseWrapper;
const BodyWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/body_wrapper").BodyWrapper;
const ActionWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/action_wrapper").ActionWrapper;
const DeleteActionWrapper = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/delete_action_wrapper").DeleteActionWrapper;
const SuccessResponse = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/success_response").SuccessResponse;
const APIException = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/api_exception").APIException;
const ZCRMShareRecord = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/share_records/share_record").ShareRecord;
const ZCRMUser = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/users/user").User;
class ShareRecord{
/**
* Revoke Shared Record
* This method is used to revoke access to a shared record that was shared to users and print the response.
* @param {String} moduleAPIName The API Name of the module to revoke shared record.
* @param {BigInt} recordId The ID of the record
*/
static async revokeSharedRecord(moduleAPIName, recordId){
//example
//let moduleAPIName = "Contacts";
// let recordId = 3409643000002112011n;
//Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
let shareRecordsOperations = new ShareRecordsOperations(recordId, moduleAPIName);
//Call revokeSharedRecord method
let response = await shareRecordsOperations.revokeSharedRecord();
if(response != null){
//Get the status code from response
console.log("Status Code: " + response.statusCode);
//Get object from response
let responseObject = response.object;
if(responseObject != null){
//Check if expected ActionWrapper instance is received
if(responseObject instanceof DeleteActionWrapper){
let deleteActionResponse = responseObject.getShare();
if(deleteActionResponse instanceof SuccessResponse){
console.log("Status: " + deleteActionResponse.getStatus().getValue());
console.log("Code: " + deleteActionResponse.getCode().getValue());
console.log("Details");
let details = deleteActionResponse.getDetails();
if(details != null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + deleteActionResponse.getMessage().getValue());
}
else if(actionResponse instanceof APIException){
console.log("Status: " + deleteActionResponse.getStatus().getValue());
console.log("Code: " + deleteActionResponse.getCode().getValue());
console.log("Details");
let details = deleteActionResponse.getDetails();
if(details != null){
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
console.log("Message: " + deleteActionResponse.getMessage().getValue());
}
}
//Check if the request returned an exception
else if(responseObject instanceof 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());
}
}
}
}
}
module.exports = {ShareRecord}