Hide choices on select box based on the requested for user company on catalog item

jitendrag
Tera Expert

Hi!

I have a select box where I have choice1,choice2,choice3,choice4,choice5. If the requested for user is belongs to company record field 'u_field_name1'==true or 'u_field_name2'==true then I need to show all five options else I need only first two options. For this I have created a client callable script and created a on change catalog client script. But some how this is not working. 

 

Can some one explain me how can I achieve this and what am I doing wrong. Posting my code here

 

ScriptInclude:

var CheckrequestedforCompany = Class.create();
CheckrequestedforCompany.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    fixChoiceOptions: function(){
 var userId = this.getParameter('sysparm_sys');
 var userGR = new GlideRecord('sys_user');
 userGR.addQuery('sys_id',userId);
 userGR.query();
 if(userGR.next()){
    if(userGR.company.field_name1==true || userGR.company.field_name2 == true){
        return true;
    }
    else{
        return false;
    }
 
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var requestedFor = g_form.getValue('requested_for');
   //Type appropriate comment here, and begin script below
   var userCompanyDetails = new GlideAjax('CheckrequestedforCompany');
   userCompanyDetails.addParam('sysparm_name','fixChoiceOptions');
   userCompanyDetails.addParam('sysparm_sys',requestedFor);
    userCompanyDetails.getXML(removeOptions);

    function removeOptions(response){
        var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
        if (answer== false){
            alert('ok')
            g_form.removeOption('select_date','365');
        }
    }
}
 
 }
    },
    type: 'CheckrequestedforCompany'
});
1 ACCEPTED SOLUTION

jitendrag
Tera Expert

Found what is wrong. I have added  a role ACL which is not allowing other users to run the script. So added

 isPublic:function(){return true;},

View solution in original post

7 REPLIES 7

Yes.... I just put the code as reference. But I am using u_ for my fields as they are custom fields

@jitendrag 

 

Can you please share the complete Script Include and Client Script ? Also, I can see you have an alert in the client script. Are you getting any output from your client script via that ?


Please mark this response as correct and helpful if it assisted you with your question.

jitendrag
Tera Expert

Found what is wrong. I have added  a role ACL which is not allowing other users to run the script. So added

 isPublic:function(){return true;},