The CreatorCon Call for Content is officially open! Get started here.

make checkbox visible to certain group

kunal16
Tera Expert

I have a requirement that on the incident form, show a checkbox field - Escalation to only members of the group 'Service Desk' or users having role 'admin'

Also, if the checkbox is set to 'true', make the work notes mandatory, otherwise if the checkbox is false, make work notes non-mandatory.

I have written a script include for group check -

var getSerDeskgroup = Class.create();

getSerDeskgroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  myServiceDesk : function()

  {

            if ((gs.getUser().isMemberOf('Service Desk')) || (gs.hasRole('admin')))

            {

                      return true;

            }

            else

            {

                      return false;

            }

  },

  type: 'getSerDeskgroup'

});

And the onChange (of Escalation) client script is

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

  if (isLoading || newValue === '') {

            return;

  }

  if (newValue != '')

  {

            alert('Escalation is checked ' + newValue);

            var ga = new GlideAjax('getSerDeskgroup');

            ga.addParam('sysparm_name', 'myServiceDesk');

            ga.getXML(parseMember);

  }

  function parseMember(response)

  {

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

            if (answer == 'true')

            {

                      g_form.setMandatory('work_notes', true);

            }

  }

  if (newValue == false)

  {

            alert('Escalation is unchecked ' + newValue);

            g_form.setMandatory('work_notes', false);

  }

}

It seems the functionality is not working as expected

Any help on this will be appreciated.

Thanks in advance!!

1 ACCEPTED SOLUTION

nataraj_snow
Giga Contributor

Below 2 cusomizations should resolve your issue :



1. Wrie an UI policy on incident form as shown below :


find_real_file.png




2. Write 2 similar ACLs (1 for READ, other for WRITE) as shown below:


find_real_file.png



I tried this and this resolved the issue. You can try it, and if it works please mark it CORRECT answer.


View solution in original post

14 REPLIES 14

Hi Deepa, Thanks for your reply but still I am getting the same error:



find_real_file.png


Can you please give the screenshot of ur Script include and CS.


Hi Deepa,



Below are the script include and client script:



1. Script Include


var getmyCheckbox = Class.create();


getmyCheckbox.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  getServicgroup : function()


  {


            if (gs.getUser().isMemberOf('Service Desk'))


            {


                      return true;


            }


            else


            {


                      return false;


                      }


  },


  type: 'getmyCheckbox'


});



2. Client script


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


        if (isLoading && newValue=='false' )


        {      


            return;


        }


        if (newValue == 'true')  


        {


                  alert('Escalation is checked ' + newValue);  


                  var ga = new GlideAjax('getSerDeskgroup');  


                  ga.addParam('sysparm_name', 'myServiceDesk');  


                  ga.getXML(parseMember);          


        }


        else


        {


                  alert('Escalation is unchecked ' + newValue);


                  g_form.setMandatory('work_notes', false);


        }




        function parseMember(response)  


        {      


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


                  if (answer == 'true')


                  {              


                            g_form.setMandatory('work_notes', true);


                  }


        }


}


I can see there is diff name present in your CS for script include and function...


Replace this with below:-


  var ga = new GlideAjax('getmyCheckbox');      


  ga.addParam('sysparm_name', 'getServicgroup');      


Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


Oops!!! That was a typo error from my end. Even with the changes it showing me the same error.