Skip to main content

Node JS SDK Samples - Blueprint Operations

Get Blueprint Details
Update Blueprint
              
              
const ZCRMBluePrint = require("zcrmsdk/core/com/zoho/crm/api/blue_print/blue_print").BluePrint;
const ZCRMRecord = require("zcrmsdk/core/com/zoho/crm/api/record/record").Record;
const BluePrintOperations = require("zcrmsdk/core/com/zoho/crm/api/blue_print/blue_print_operations").BluePrintOperations;
const ResponseWrapper = require("zcrmsdk/core/com/zoho/crm/api/blue_print/response_wrapper").ResponseWrapper;
const BodyWrapper = require("zcrmsdk/core/com/zoho/crm/api/blue_print/body_wrapper").BodyWrapper;
const APIException = require("zcrmsdk/core/com/zoho/crm/api/blue_print/api_exception").APIException;
const SuccessResponse = require("zcrmsdk/core/com/zoho/crm/api/blue_print/success_response").SuccessResponse;
const Transition = require("zcrmsdk/core/com/zoho/crm/api/blue_print/transition").Transition;
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 BluePrintOperations(recordId, moduleAPIName);

        //Get instance of BodyWrapper Class that will contain the request body
        let bodyWrapper = new BodyWrapper();

        //Array to contain BluePrint instances
        let bluePrintArray = [];

        //Get instance of BluePrint Class
        let bluePrint = new ZCRMBluePrint();

        //Set transitionId to the BluePrint instance
        bluePrint.setTransitionId(transitionId);

        //Get instance of Record Class
        let data = new ZCRMRecord();

        let lookup = new Map();

        lookup.set("Phone", "8940372937");
        
        lookup.set("id", "8940372937");
        
        // data.addKeyValue("Data_3", lookup);

        data.addKeyValue("Phone", "8940372937");
        
        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 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 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 = {BluePrint}