JavaScript SDK Samples - Share Records Operations
class SharedRecord
{
/**
* 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 = 34096432112011n;
//Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
let sharedRecordsOperations = new ZCRM.ShareRecord.Operations(recordId, moduleAPIName);
//Get instance of BodyWrapper Class that will contain the request body
let request = new ZCRM.ShareRecord.Model.BodyWrapper();
//Array to hold ShareRecord instances
let shareRecordArray = [];
for (let i = 0; i {
//Check if the request is successful
if (actionResponse instanceof ZCRM.ShareRecord.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.ShareRecord.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.ShareRecord.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 SharedRecord
{
/**
* 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 = 34096432112011n;
//Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
let sharedRecordsOperations = new ZCRM.ShareRecord.Operations(recordId, moduleAPIName);
//Get instance of BodyWrapper Class that will contain the request body
let request = new ZCRM.ShareRecord.Model.BodyWrapper();
//Array to hold ShareRecord instances
let shareRecordArray = [];
//Get instance of ShareRecord
let shareRecord = new ZCRM.ShareRecord.Model.ShareRecord();
//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 ZCRM.User.Model.User();
//Set ID to the User
user.setId(34770615791024n);
//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.getStatusCode());
//Get object from response
let responseObject = response.getObject();
if (responseObject != null) {
//Check if expected ActionWrapper instance is received
if (responseObject instanceof ZCRM.ShareRecord.Model.ActionWrapper) {
//Get the array of obtained ActionResponse instances
let actionResponses = responseObject.getShare();
actionResponses.forEach(actionResponse => {
//Check if the request is successful
if (actionResponse instanceof ZCRM.ShareRecord.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.ShareRecord.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.ShareRecord.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 SharedRecord
{
/**
* 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 = 34096432112011n;
//Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
let shareRecordsOperations = new ZCRM.ShareRecord.Operations(recordId, moduleAPIName);
//Call revokeSharedRecord method
let response = await shareRecordsOperations.revokeSharedRecord();
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.ShareRecord.Model.DeleteActionWrapper) {
let deleteActionResponse = responseObject.getShare();
if (deleteActionResponse instanceof ZCRM.ShareRecord.Model.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 ZCRM.ShareRecord.Model.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 ZCRM.ShareRecord.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());
}
}
}
}
}