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

Community Alums
Not applicable

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

12 REPLIES 12

@Community Alums can you please give me a screenshot of where you are calling the script include.

Community Alums
Not applicable

Hi @Arun_S1 , It's in the default value of the multiple choice field

RJ8_0-1686779392953.png

 

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'

});

 

@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');

 

Arun_S1_0-1686825215382.png

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.