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

jitendrag
Tera Expert

@Ankur Bawiskar  Any help would be appreciated.

 

Amit Verma
Kilo Patron
Kilo Patron

Hi @jitendrag 

 

Can you please let me know what you are trying to check with this line of code userGR.company.field_name1==true ?  Do you have field_name1 as custom field on company table ?

 

If yes, you need to pass it as userGR.company.u_field_name1==true and userGR.company.u_field_name2==true as these are user-defined fields.

 

Thanks and Regards

Amit Verma


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

Hi,

 

I am using the u_field_name1 == true only

@jitendrag 

 

Is it a custom field ? Also, as per the code provided by you, you are not using it as u_field_name1. See below :

if(userGR.next()){
    if(userGR.company.field_name1==true || userGR.company.field_name2 == true) // You are directly calling field_name1 field instead of u_field_name1
{
        return true;
    }

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