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.

How to access catalog item variable and make mandatory on change of malty row variableset ServiceNow

Nandu4
Tera Contributor

I have scenario where if more than 5 ip address are getting added through new request or existing , i need to show message and make addtional comment feild mandatory as mandatory which is in catalog item. So i have write script onchange of ip address which is mrv message is working fine but mandatory is not working 

 

var partner_id = g_service_catalog.parent.getValue("u_aoi_partner");

    var aoc_ga = new GlideAjax("XXXXXX");

    aoc_ga.addParam("sysparm_name", "getRowCountofipAddress");

    aoc_ga.addParam("partner_info", partner_id);

    aoc_ga.getXMLAnswer(result);

 

    function result(response) {

        var rowCountofIPAddress = parseInt(response, 10);

        if (rowCountofIPAddress < 5) {

            var mrvs = g_service_catalog.parent.getValue('ip_address_to_be_added');

           

            if (mrvs.length > 2) {

                var mrvsData = parseInt((JSON.parse(mrvs).length), 10);

                var totalRowCount = mrvsData + rowCountofIPAddress;

                if (totalRowCount == 5) {

                    g_form.setMandatory('u_aoi_additional_information', true);

                    g_form.showFieldMsg("u_aoi_ip_address", "More than 5 IP Addresses have been requested or are already whitelisted for your Company. Please provide a justification of the need in the field below.");

                }

            }

        } else {

           g_form.setMandatory('u_aoi_additional_information', true);

            g_form.showFieldMsg("u_aoi_ip_address", "More than 5 IP Addresses have been requested or are already whitelisted for your Company. Please provide a justification of the need in the field below.");

        }

    }

0 REPLIES 0