JavaScript SDK Samples - Blueprint Operations
Get Blueprint Details
Update Blueprint
class Blueprint
{
/**
* Update Blueprint
* This method is used to update a single record's Blueprint details with ID and print the response.
* @param {String} moduleAPIName The API Name of the record's module
* @param {BigInt} recordId The ID of the record to update Blueprint
* @param {BigInt} transitionId The ID of the Blueprint transition Id
*/
static async updateBlueprint(moduleAPIName, recordId, transitionId) {
//example
// let moduleAPIName = "Leads";
// let recordId = 34096432469044n;
// let transitionId = 34096431172075n;
//Get instance of BluePrintOperations Class that takes moduleAPIName and recordId as parameter
let bluePrintOperations = new ZCRM.BluePrint.Operations(recordId, moduleAPIName);
//Get instance of BodyWrapper Class that will contain the request body
let bodyWrapper = new ZCRM.BluePrint.Model.BodyWrapper();
//Array to contain BluePrint instances
let bluePrintArray = [];
//Get instance of BluePrint Class
let bluePrint = new ZCRM.BluePrint.Model.BluePrint();
//Set transitionId to the BluePrint instance
bluePrint.setTransitionId(transitionId);
//Get instance of Record Class
let data = new ZCRM.Record.Model.Record();
let lookup = new Map();
lookup.set("Phone", "892937");
lookup.set("id", "894937");
// data.addKeyValue("Data_3", lookup);
data.addKeyValue("Phone", "8942937");
data.addKeyValue("Notes", "Updated via blueprint");
let checkLists = [];
let checkListItem = new Map();
checkListItem.set("list 1", true);
checkLists.push(checkListItem);
checkListItem = new Map();
checkListItem.set("list 2", true);
checkLists.push(checkListItem);
checkListItem = new Map();
checkListItem.set("list 3", true);
checkLists.push(checkListItem);
data.addKeyValue("CheckLists", checkLists);
//Set data to the BluePrint instance
bluePrint.setData(data);
//Add BluePrint instance to the array
bluePrintArray.push(bluePrint);
//Set the array to bluePrint in BodyWrapper instance
bodyWrapper.setBlueprint(bluePrintArray);
//Call updateBluePrint method that takes BodyWrapper instance
let response = await bluePrintOperations.updateBlueprint(bodyWrapper);
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) {
if (responseObject instanceof ZCRM.BluePrint.Model.SuccessResponse) {
//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());
}
else if (responseObject instanceof ZCRM.BluePrint.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 + ": ");
var data = details.get(key);
if (Array.isArray(data)) {
for (let error of data) {
console.log("Field APIName " + error.getAPIName() + " : " + error.getMessage());
}
}
else {
console.log(JSON.stringify(data));
}
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}