How to hide values of subcategory

vivian08081
Giga Expert

So far we have plenty incident tickets already existing in our instance. We don't want to deactivate any value from subcategory.

Just want to users could not see them from the drop down list.

I try to use client script - onChange - g_form.removeOption('subcategory','email') to implement this. But it doesn't work for the reference fields like subcategory..

Does anyone have any idea to implement this?

1 ACCEPTED SOLUTION

Hi Wei,



I have tried below and it works, let me try to explain in details if this helps. Created a column (Right Click on the list header then configure -> List Layout) on sys_choice table and then create a new column Choice Not Needed (true/false type) and set the value to true for the records which you don't want to display. Refer the screen shot below.


find_real_file.png


find_real_file.png



then create a script include with below code. You might need to fine tune the code based upon your field name.


var GetListValue = Class.create();


GetListValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {


getList : function()


{


var ids = [];


var gr = new GlideRecord('sys_choice');


gr.addQuery('dependent_value', current.u_category.value); //Considering category is also a reference field.


gr.addQuery('name', 'incident');


gr.addQuery('u_choice_not_needed', 'false');


gr.query();


while(gr.next())


ids.push(gr.sys_id.toString());


return 'sys_idIN' + ids;


},


type: 'GetListValue'


});



and then set the reference qualifier on subcategory field like below.


find_real_file.png



Result: It's displaying the value of subcategory for which Choice Not Needed is set to false


find_real_file.png


View solution in original post

27 REPLIES 27

for your solution, do you mean change the field subcategory's type from string to reference like below?


find_real_file.png


find_real_file.png


You can not change the existing type from string to reference since reference type field will always have 32 characters. As per the post "it doesn't work for the reference fields like subcategory"   looks like you are using the subcategory as reference field,then why are converting the existing field type. I believe you should be using subcategory as reference field.



Is your Subcategory field is type string? If yes,then we need to have different approach (onChange() + GlideAjax (script include)) with same concept to avoid getting the choice which we do not want.


unfortunately, so far the Subcategory field Type is String, not reference.



So could you give another solution for this?


find_real_file.png


By the way, the subcategory is dependent on field Category


find_real_file.png


Please try in this way then, see if this helps.



Client Script:


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


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


return;      


}    


g_form.clearOptions('subcategory');


var ga = new GlideAjax('GetListValue');  


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


ga.addParam('sysparm_cat', newValue);  


ga.getXML(fillDetails);  


function fillDetails(serverResponse)  


{  


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


alert(answer);


var choiceval = answer.split(',');


for(var i = 0; choiceval.length > i ; i++){


g_form.addOption('subcategory', choiceval[i], choiceval[i], [i]);


}


}  


}  



Client Callable Script Include:


var GetListValue = Class.create();


GetListValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {


getList : function()


{


var ids = [];


var gr = new GlideRecord('sys_choice');


gr.addQuery('dependent_value', this.getParameter('sysparm_cat'));


gr.addQuery('name', 'incident');


gr.addQuery('u_choice_not_needed', false);


gr.query();


while(gr.next())


ids.push(gr.label.toString());


return '' + ids;


},


type: 'GetListValue'


});