The CreatorCon Call for Content is officially open! Get started here.

Populate MRVS variables on RITM Description

Ankita Gupte
Kilo Sage

Hello Experts,

 

I tried below script to populate MRVS in RITM Description, but values displayed are sysid. Please advice

 

var desc = '';
var mrvs = current.variables.vs_asset_information;
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
var row = mrvs.getRow(i);
desc += "Row " + i+1 + " : Model Category :" + row.var_model_category + " Model : " + row.var_model + " Serial Number :" + row.var_serial_number + " Assigned to User Name : " + row.assigned_to_user_name_serial_Number + " Net book value of the asset : " + row.net_book_value_of_the_asset + " Warranty expiry date : " + row.warranty_expiry_date + " Asset end of Life date : " + row.asset_end_of_life_date + "\n";
}
current.description = desc;

 

AnkitaGupte_1-1731335604502.png

 

1 ACCEPTED SOLUTION

I modified script as below and it worked perfectly fine

 

var desc = '';
var mrvs = JSON.parse(current.variables.vs_asset_information);  // Parsing the JSON asset data
var rowCount = mrvs.length;  // Assuming mrvs is an array

for (var i = 0; i < rowCount; i++) {
    // GlideRecord to get Model Category Name
    var modelCategoryName = '';
    if (mrvs[i].var_model_category) {
        var modelCategoryGR = new GlideRecord('cmdb_model_category'); // Replace with actual table name
        if (modelCategoryGR.get(mrvs[i].var_model_category)) {
            modelCategoryName = modelCategoryGR.name;  // Assuming 'name' is the field for Model Category Name
        }
    }

    // GlideRecord to get Model Name
    var modelName = '';
    if (mrvs[i].var_model) {
        var modelGR = new GlideRecord('cmdb_model'); // Replace with actual table name
        if (modelGR.get(mrvs[i].var_model)) {
            modelName = modelGR.display_name;  // Assuming 'name' is the field for Model Name
        }
    }

    // GlideRecord to get Assigned User Name
    var assignedToUserName = '';
    if (mrvs[i].assigned_to_user_name_serial_Number) {
        var userGR = new GlideRecord('sys_user'); // sys_user table for users
        if (userGR.get(mrvs[i].assigned_to_user_name_serial_Number)) {
            assignedToUserName = userGR.name;  // Assuming 'name' is the field for User Name
        }
    }

    // Constructing description string with names instead of sys_id
    desc += "Row " + (i + 1) + " : Model Category : " + modelCategoryName + 
            "; Model Name: " + modelName + 
            "; Serial Number : " + mrvs[i].var_serial_number + 
            "; Assigned to User Name : " + assignedToUserName + 
            "; Net book value of the asset : " + mrvs[i].net_book_value_of_the_asset + 
            "; Warranty expiry date : " + mrvs[i].warranty_expiry_date + 
            "; Asset end of Life date : " + mrvs[i].asset_end_of_life_date + "\n";
}

current.description = desc;  // Setting the generated description

To fetch the name/display name for this instead of sysid I GlideRecord each table and got the values

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

var desc = '';
var mrvs = JSON.parse(current.variables.vs_asset_information);
var rowCount = mrvs.getRowCount();
for (var i = 0; i < mrvs.length; i++) {
//var row = mrvs.getRow(i);
desc += "Row " + i +1 + " : Model Category :" + mrvs[i].var_model_category + " Model : " + mrvs[i].var_model + " Serial Number :" + mrvs[i].var_serial_number + " Assigned to User Name : " + mrvs[i].assigned_to_user_name_serial_Number + " Net book value of the asset : " + mrvs[i].net_book_value_of_the_asset + " Warranty expiry date : " + mrvs[i].warranty_expiry_date + " Asset end of Life date : " + mrvs[i].asset_end_of_life_date + "\n";
}
current.description = desc;

Hi Joro, Greeting of the day!

The vaues are still showing as sysid 

AnkitaGupte_0-1731388456838.png

I modified script as below and it worked perfectly fine

 

var desc = '';
var mrvs = JSON.parse(current.variables.vs_asset_information);  // Parsing the JSON asset data
var rowCount = mrvs.length;  // Assuming mrvs is an array

for (var i = 0; i < rowCount; i++) {
    // GlideRecord to get Model Category Name
    var modelCategoryName = '';
    if (mrvs[i].var_model_category) {
        var modelCategoryGR = new GlideRecord('cmdb_model_category'); // Replace with actual table name
        if (modelCategoryGR.get(mrvs[i].var_model_category)) {
            modelCategoryName = modelCategoryGR.name;  // Assuming 'name' is the field for Model Category Name
        }
    }

    // GlideRecord to get Model Name
    var modelName = '';
    if (mrvs[i].var_model) {
        var modelGR = new GlideRecord('cmdb_model'); // Replace with actual table name
        if (modelGR.get(mrvs[i].var_model)) {
            modelName = modelGR.display_name;  // Assuming 'name' is the field for Model Name
        }
    }

    // GlideRecord to get Assigned User Name
    var assignedToUserName = '';
    if (mrvs[i].assigned_to_user_name_serial_Number) {
        var userGR = new GlideRecord('sys_user'); // sys_user table for users
        if (userGR.get(mrvs[i].assigned_to_user_name_serial_Number)) {
            assignedToUserName = userGR.name;  // Assuming 'name' is the field for User Name
        }
    }

    // Constructing description string with names instead of sys_id
    desc += "Row " + (i + 1) + " : Model Category : " + modelCategoryName + 
            "; Model Name: " + modelName + 
            "; Serial Number : " + mrvs[i].var_serial_number + 
            "; Assigned to User Name : " + assignedToUserName + 
            "; Net book value of the asset : " + mrvs[i].net_book_value_of_the_asset + 
            "; Warranty expiry date : " + mrvs[i].warranty_expiry_date + 
            "; Asset end of Life date : " + mrvs[i].asset_end_of_life_date + "\n";
}

current.description = desc;  // Setting the generated description

To fetch the name/display name for this instead of sysid I GlideRecord each table and got the values