Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

REcord producer How to display Multi row variable set data values in the description of the request

GD00609570
Tera Contributor

Hi Team, my code is not working and not getting MRVS values in the description of the request using REcord producer Script, could you please review the below code and correct as priority.

 

Code:

 

(function() {
    var desStr = ""; // Build Description

    // Helper: safely get display for a choice/reference variable; fallback to value
    function getDisplay(varName) {
        try {
            if (producer.variables && producer.variables[varName] && producer.variables[varName].getDisplayValue) {
                return producer.variables[varName].getDisplayValue();
            }
        } catch (e) {
            // ignore and fallback
        }
        return producer[varName];
    }

    // Helper: add a labeled line if value exists
    function addLine(label, value) {
        if (value !== null && value !== undefined && value !== "") {
            desStr += label + ": " + value + "\n";
        }
    }

    // Read operations value and display
    var operationsValue = producer.operations;          
    var operationsDisplay = getDisplay('operations');    

    if (operationsValue == "create") {
        addLine("Operations", operationsDisplay);
        addLine("Details", producer.details);


        desStr += " CI Details: \n\n";
        gs.log('cmdb rec ....'+producer.cmdb_action.getDisplayValue() + ",,,,,,,,,,,,,,,,,,,,,,,,,,,"+ producer.cmdb_action);

        // CMDB block (add only when present)
        addLine("CMDB Action", producer.cmdb_action);
        addLine("Name", producer.variables.name);
        addLine("Company Name", producer.company_name);
        addLine("Location", producer.location);
        addLine("Manufacturer", producer.manufacturer);
        addLine("Model ID", producer.model_id);
        addLine("Hardware", producer.hardware);
        addLine("Description", producer.description);
        addLine("Serial Number", producer.serial_number);
        addLine("Management IP", producer.management_ip);
        addLine("MAC Address", producer.mac_address);
        addLine("Primary Supplier", producer.primary_supplier);
        addLine("Secondary Supplier", producer.secondary_supplier);
        addLine("Maintenance SLA", producer.maintenance_sla);
        addLine("Notes", producer.notes);
        addLine("Validation Information", producer.validation_information);
        desStr += "\n";
        gs.log('cmdb rec 2 ....'+desStr);

    } else if (operationsValue == "update" || operationsValue == "retire") {
        // If cmdb_ci is a reference variable, this prints the display name
        var cmdbCiDisplay = getDisplay('cmdb_ci');
        addLine("Operations", operationsDisplay);
        addLine("Details", producer.details);
         desStr += "\n";
        addLine("CMDB/CI", cmdbCiDisplay);

    } else {
        addLine("Operations", operationsDisplay);
        addLine("Details", producer.details);
    }

    current.description = desStr;
})
();
 

Thanks,

1 REPLY 1

vaishali231
Tera Guru

hey @GD00609570 


Try this :

(function() {

    var desStr = "";

    function getDisplay(varName) {
        try {
            if (producer.variables[varName] && producer.variables[varName].getDisplayValue) {
                return producer.variables[varName].getDisplayValue();
            }
        } catch (e) {}
        return producer[varName];
    }

    function addLine(label, value) {
        if (value) {
            desStr += label + ": " + value + "\n";
        }
    }

    var operationsValue = producer.operations;
    var operationsDisplay = getDisplay('operations');

    // ---------------- CREATE ----------------
    if (operationsValue == "create") {

        addLine("Operations", operationsDisplay);
        addLine("Details", producer.details);

        desStr += "\nCI Details:\n";

        //  IMPORTANT: Replace 'cmdb_details' with your MRVS name
        var mrvs = producer.cmdb_details;

        if (mrvs) {
            var rows = JSON.parse(mrvs);

            for (var i = 0; i < rows.length; i++) {

                desStr += "\n--- Row " + (i + 1) + " ---\n";

                addLine("Company Name", rows[i].company_name);
                addLine("Location", rows[i].location);
                addLine("Manufacturer", rows[i].manufacturer);
                addLine("Model ID", rows[i].model_id);
                addLine("Hardware", rows[i].hardware);
                addLine("Description", rows[i].description);
                addLine("Serial Number", rows[i].serial_number);
                addLine("Management IP", rows[i].management_ip);
                addLine("MAC Address", rows[i].mac_address);
                addLine("Primary Supplier", rows[i].primary_supplier);
                addLine("Secondary Supplier", rows[i].secondary_supplier);
                addLine("Maintenance SLA", rows[i].maintenance_sla);
                addLine("Notes", rows[i].notes);
                addLine("Validation Information", rows[i].validation_information);
            }
        }

    }

    // ---------------- UPDATE / RETIRE ----------------
    else if (operationsValue == "update" || operationsValue == "retire") {

        addLine("Operations", operationsDisplay);
        addLine("Details", producer.details);

        var cmdbCiDisplay = getDisplay('cmdb_ci');
        addLine("CMDB/CI", cmdbCiDisplay);
    }

    // ---------------- DEFAULT ----------------
    else {
        addLine("Operations", operationsDisplay);
        addLine("Details", producer.details);
    }

    current.description = desStr;

})();


*************************************************************************************************************************************

If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh