Set multiple-choice variable default value if more than one records show up in list collector field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2023 06:13 AM
I have a catalog item where I want to set the default value of a multiple-choice field based on the data that shows up on another list collector (this data varies based on another reference field) field.
My multiple-choice field has 3 options (Option 1, Option 2, and Option 3).
If the list collector field displays one record in the drop-down, I want Option 1 to be selected by default for the multiple-choice field.
If the list collector field displays more than one record in the drop-down, I want Option 3 to be selected by default for the multiple-choice field.
Please let me know if anyone can think of a way to implement this.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 11:58 AM
@Community Alums can you please give me a screenshot of where you are calling the script include.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 02:51 PM
Hi @Arun_S1 , It's in the default value of the multiple choice field
Here is the script include
var SiteCount = Class.create();
SiteCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {},
return_count: function(query) {
gs.addErrorMessage('In Script Include123');
gs.addErrorMessage(query);
var loc_rec = new GlideRecord('cmn_location');
loc_rec.addEncodedQuery(query);
loc_rec.query();
if (loc_rec.next()) {
var row_count = loc_rec.getRowCount();
gs.info(row_count);
if (row_count == 1) {
return 1;
} else {
return 3;
}
}
},
type: 'SiteCount'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2023 03:34 AM
@Community Alums I have modified the script include script to
function SiteCount(query) {
gs.addErrorMessage('In Script Include123');
gs.addErrorMessage(query);
var loc_rec = new GlideRecord('cmn_location');
loc_rec.addEncodedQuery(query);
loc_rec.query();
if (loc_rec.next()) {
var row_count = loc_rec.getRowCount();
gs.addErrorMessage(row_count);
if (row_count == 1) {
return 2;
} else {
return 3;
}
} else{
return 1;
}
}
Used the below script in the default value:
javascript:SiteCount('phone=503-373-7051');
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.