- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 06:33 AM
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;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 11:00 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 08:04 AM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 09:14 PM
Hi Joro, Greeting of the day!
The vaues are still showing as sysid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 11:00 PM
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