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

Catalog Client Script - g_form.removeOption / g_form.removeOption is not working

Miko_aj Buczek
Tera Contributor

Hello,

 

I have a task to add/remove choices from sub_unit_1 variable based on choices from business_unit_1 variable. 

Business_unit_1 is a reference to table "u_business_unit", label '"name", and sub_unit_1 is lookup selectbox ( also reference to table "u_business_unit", label "name")

Code below is not working. Please, assist. Thanks

 

Miko_ajBuczek_0-1668766814389.png

 

1 ACCEPTED SOLUTION

You should provide below parameters while using addOption method :

 

g_form.addOption("sub_unit1", "All employee", "All employee", 1);

g_form.addOption("sub_unit1", "ATF Test", "ATF Test", 2);

 

Please mark answer as Correct or Helpful based on impact.

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Can you confirm that  'All Employee' and 'ATF Test' are choice values and not labels?

 

This is how it should be

g_form. removeOption(<fieldName>, <choiceValue>);

-Anurag

SUBHAM AGARWAL
Tera Guru

Hello,

There is one way you can achieve this. In the reference qualifier of the sub_unit_1 field you need to call a scrip include. In that script include you will check the value of Business_unit_1  field if it a new filed then you will change encoded query otherwise it will be same and return it back.

 

Reference qualifier code will be like = javascript&colon; new checkRecordType().checktype();

 

The script include code will be like - 

 

var checkRecordType = Class.create();
checkRecordType.prototype = {
initialize: function() {
},
checktype : function()
{
var platform = current.variables.Business_unit_1.getDisplayValue()  ;// it will get value of new or existing request 
var encodedquery ='^EQ';
if(abc=='security')
{
encodedquery ='encoded query after removing the two values from table and paste here'+encodedquery; 
}

return encodedquery;
},
type: 'checkRecordType'
};

Miko_aj Buczek
Tera Contributor

Okay, i have fixed removeOption, but addOption is not working. Options are being removed, but they are not being added

Miko_ajBuczek_0-1668768952742.png

Miko_ajBuczek_0-1668769487505.png

 

 

 

 

You should provide below parameters while using addOption method :

 

g_form.addOption("sub_unit1", "All employee", "All employee", 1);

g_form.addOption("sub_unit1", "ATF Test", "ATF Test", 2);

 

Please mark answer as Correct or Helpful based on impact.

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP