Catalog client script to remove drop down value if the values starts with SNOW

BanuMahalakshmi
Tera Contributor

Hi,

 

Need your help to remove(hide) the values starts with SNOW from the category drop down list into SP. The below script is working correctly  but i should remove dynamically instead of calling removeoption for each category.  If a new value(starts with SNOW) category is added in future, this code should remove it automatically from the particular record producer.

 

function onLoad() {
//Type appropriate comment here, and begin script below

g_form.removeOption('category', 'SNOW-Modules');
g_form.removeOption('category', 'SNOW-Compensation');

}

1 ACCEPTED SOLUTION

Phanindra N
Tera Guru

Instead of going with catalog client, can you try using reference qualifier to not show options starting with SNOW.

View solution in original post

13 REPLIES 13

Samaksh Wani
Giga Sage
Giga Sage

Hello @BanuMahalakshmi 

 

You need to Use Flow designer :-

 

Trigger Action Should be Created or Updated on the Table you need.

 

1.  Flow Logic :- IF Condition Should be  category 'Contains' SNOW

2.  THEN :- Write your script to remove the Options.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

amaradiswamy
Kilo Sage

@BanuMahalakshmi ,

 

Approach 1: You may create custom table to store the categories for which the choices should be removed, then create a script include and pass category as input and return whether to remove the choice values or not

 

Script include function:

var getCategoryDependency = Class.create();
getCategoryDependency.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkCategory:function()
	{
		var categoryVal = this.getParameter('sysparm_category');
		var gr = new GlideRecord('customtablenamehere');
		//APPLY QUERY USING FIELD NAME using addQuery
		gr.query();
		if(gr.next())
			{
				return 'found';
			}
		else
			{
				return 'not_found';
			}
	},
    type: 'getCategoryDependency'
});

Client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var ga = new GlideAjax('global.getCategoryDependency');
	ga.addParam('sysparm_name','checkCategory');
	ga.addParam('sysparm_category',newValue);
	ga.getXML(responsecallback);
	function responsecallback(response)
	{
		var ans = response.responseXML.documentElement.GetAttribute('answer');
		if(ans == 'found')
			{
			g_form.removeOption('category', 'SNOW-Modules');
g_form.removeOption('category', 'SNOW-Compensation');	
			}
	}
 
   
}

 

2. Create system property and store comma separated values of categories. In the script include using the above method call gs.getProperty() & check if the category exists or not. 

Samaksh Wani
Giga Sage
Giga Sage

Hi @BanuMahalakshmi 

 

 

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

 

if(newValue.contains('SNOW')){

   return false;

}

 

}

 

Using the Script you can make user to retrict those choices.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

SriDeepa_0-1692193717031.png

 

THanks for reply, i am getting the error message newValue.contains is not function.