Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

remove option not working on catalog client script

Nani365
Tera Contributor

I am trying to use same client script which is working on the desktop/platform . I am trying to remove options based on date range . For example : I have a request type with 5 options and I have requirement where I have to show only 2 choices under request type from November - March . I tried onload client script for desktop where I passed date range as json and used gs_form.removeOption(‘request_type’, ,’bonus_form’);

5 REPLIES 5

Nani365
Tera Contributor
function onLoad() {
    var requestType = g_form.getValue('request_type');
    var dateRanges = {
        "annual_bonuses": {
            "start": "2024-02-01",
            "end": "2024-02-28"
        },
       
    };
    processRequestTypes(dateRanges);
    function isRequestTypeVisible(requestTypeValue, dateRanges) {
        var currentDate = new Date();
        if (dateRanges.hasOwnProperty(requestTypeValue)) {
            var startDate = new Date(dateRanges[requestTypeValue].start);
            var endDate = new Date(dateRanges[requestTypeValue].end);
            return currentDate >= startDate && currentDate <= endDate;
        }
        return false;
    }
    function processRequestTypes(dateRanges) {
        for (var keyID in dateRanges) {
            if (dateRanges.hasOwnProperty(keyID)) {
                if (!isRequestTypeVisible(keyID, dateRanges)) {
                    switch (keyID) {
                        case 'annual_bonuses':
                            g_form.removeOption('request_type', 'annual_bonuses');
                            break;
                           
                    }
                }

            }
        }

        // Show choices based on the specified timings and date ranges

    }


}