Need Help on List type Field Validation

Nagesh5
Tera Contributor

Hello Experts,

 

We have list type field on the form where we can choose different options and we are looking for the way to check if particular string identified in the list type then it should set some other fields mandatory through client script it will be great help if anyone send code snippet.

 

Thanks,

Nagesh K

3 REPLIES 3

Slava Savitsky
Giga Sage

With that amount of information, there is no way we can help you. What have you already tried? And what exactly does not work?

Thanks for update and tried below logic and it's not working. Can you help where exactly i was missing the logic?

 

Client Script :--------------------

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var ga = new GlideAjax("checkUser");
    ga.addParam("sysparm_name", "getUsers");
    ga.addParam("sysparm_value", g_form.getValue("user_check"));
    ga.getXML(userCheck);

    function userCheck(response) {

        var answer = response.responseXML.documentElement.getAttribute("answer");

        //var ouput = JSON.parse(answer);

        if(answer.includes("albert")){

            g_form.setMandatory("Requester",true);
        }

    }
}
 
Script Include ------------------
 
var checkUser = Class.create();
checkUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getUsers: function() {

        var checkValues = this.getParameter("sysparm_value");
        //var arr = checkValues(",");
        //for (var i = 0; i < arr.length; i++) {
            var croles = new GlideRecord('sys_user');
            croles.addQuery('sys_id', checkValues);
            croles.query();
            var arrRoles = [];
            if (croles.next()) {

                gs.info("*******Users" + croles.getDisplayValue());
                //Fill array
                //var arr =croles.split(",");
                arrRoles.push(croles.getDisplayValue().toString());

            //}
        }
        return arrRoles.toString();

    },

    type: 'checkUser'
});
 
Thanks,
Nagesh

What is your script supposed to do? What exactly does not work?