- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:25 AM - edited 11-18-2022 02:28 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 03:05 AM
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.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:28 AM - edited 11-18-2022 02:29 AM
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>);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:40 AM
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: 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'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:56 AM - edited 11-18-2022 03:04 AM
Okay, i have fixed removeOption, but addOption is not working. Options are being removed, but they are not being added
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 03:05 AM
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.
Regards,
Abhijit
ServiceNow MVP