- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
In MRVS how to get only 1st Category from multiple Model Categories
Under cmdb_model table we have field Model Categories how i can take only first Category and add to MRVS data.
Now adding it takes all the categories.
Example:
Model Categories- Disk,Server,Linux,test
in MRVS i need only first Record to add here is 'Disk' how to get only 1st Value.
Thanks,
Shekhar,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
thats right from client script you can call the script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
here is the sample model:
Run the script in BG:
BG script:
// Server-side script for glide_list field - First category only
// Get first category from your specific model
var modelGR = new GlideRecord('cmdb_model');
if (modelGR.get('8583ce8237732000158bbfc8bcbe5dd9')) {
// Get glide_list value (comma-separated sys_ids)
var categoryList = modelGR.getValue('cmdb_model_category');
if (categoryList) {
// Get first sys_id from the list
var firstCategorySysId = categoryList.split(',')[0];
// Get the category name
var categoryGR = new GlideRecord('cmdb_model_category');
if (categoryGR.get(firstCategorySysId)) {
var firstCategoryName = categoryGR.getDisplayValue();
gs.print('Model: ' + modelGR.getDisplayValue());
gs.print('All categories: ' + modelGR.getDisplayValue('cmdb_model_category'));
gs.print('First category sys_id: ' + firstCategorySysId);
gs.print('First category name: ' + firstCategoryName);
}
}
}
// Function for reuse
function getFirstCategory(modelSysId) {
var gr = new GlideRecord('cmdb_model');
if (gr.get(modelSysId)) {
var catList = gr.getValue('cmdb_model_category');
if (catList) {
var firstCatId = catList.split(',')[0];
var catGR = new GlideRecord('cmdb_model_category');
if (catGR.get(firstCatId)) {
return catGR.getDisplayValue();
}
}
}
return '';
}
// Usage with your model:
var firstCat = getFirstCategory('8583ce8237732000158bbfc8bcbe5dd9');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks for your reply and suggestions can you let me know on MRVS how i can do this validation you mean i need to write the script include and from there i need to get on Client MRVS side?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
thats right from client script you can call the script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what type of variable are you using in MRVS? share screenshot of variable config
what did you try?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader