- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-04-2024 10:54 PM
There are 3 field .Category and SubCategory1,subCategory2.
category is independent. but subcategory1 have 'Category 'as dependent field and its choice have also assigned dependent value.
bur 'subcategory2' has 'SubCategory1 as dependent value but choices are not assigned to dependent value.
As I write onload client script and uses the removeOption() function. and it also functioning for 'category ' and 'subcategory1'.
it also functioning for 'subcategory2' but once change the category value it showing all the values which I remove when form is onloaded.
Remove option is working for choices of all categories and those have dependent values.
But it not working for choice which do not have assigned the dependent value. Does it possible?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-04-2024 11:06 PM
Hi @vaishnavi g
Explicitly Assigned Dependent Values: removeOption() will reliably remove options that are dynamically added based on explicitly assigned dependent values in ServiceNow configurations.
Handling Fields without Assigned Dependent Values: For fields like 'SubCategory2' where choices do not have explicitly assigned dependent values, removeOption() may not consistently remove options. This is because the function primarily targets options based on explicit dependencies.
Alternative Approaches: If removeOption() does not behave as expected for fields without assigned dependent values, consider alternative approaches such as resetting the entire choice list based on conditions or using server-side scripts for more complex logic.
--------------------------------------------------------------------------------------------------------------------
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-04-2024 11:06 PM
Hi @vaishnavi g
Explicitly Assigned Dependent Values: removeOption() will reliably remove options that are dynamically added based on explicitly assigned dependent values in ServiceNow configurations.
Handling Fields without Assigned Dependent Values: For fields like 'SubCategory2' where choices do not have explicitly assigned dependent values, removeOption() may not consistently remove options. This is because the function primarily targets options based on explicit dependencies.
Alternative Approaches: If removeOption() does not behave as expected for fields without assigned dependent values, consider alternative approaches such as resetting the entire choice list based on conditions or using server-side scripts for more complex logic.
--------------------------------------------------------------------------------------------------------------------
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-08-2024 02:27 AM
Thank you for your response.
I have written the client script as well server side script. Still facing the same issue. I 'm using onload client script.
when form is load this will apply on both dependent and independent choice , but when I'm changing the category field value it showing only independent choices of subcategory2.
Below is server side script:
function onLoad() {
//Type appropriate comment here, and begin script below
if (!g_user.hasRole('jgs_it_uhri')) {
var ajax2 = new GlideAjax('uhriCatDetails');
ajax2.addParam('sysparm_name', 'subCategory2');//function name
ajax2.addParam('sysparm_subcategory2', 'u_subcategory_5');//parameter
ajax2.getXML(ajaxResponse2);
function ajaxResponse2(serverResponse) {
var answer1 = JSON.parse(serverResponse.responseXML.documentElement.getAttribute("answer"));
var i = 0;
//alert('insideajaxResponse2 function');
for (i = 0; i < answer1.length; i++) {
alert("array value for subcat 2 : " + answer1[i]);
g_form.removeOption('u_subcategory_5', answer1[i]);
}
}
}
}
Could you please advice me what is wrong in this code?
after using the server side script still facing the issue for removing independent choices ? is the drawback of snow? or missing the something in above code? could you please advice?