- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2015 12:19 AM
Hi, I have two fields (Incident table) CI and Sub Category for CI's, which is a dependent to CI field. Sub Category for CI's is a choice field and will have choices based on the CI field. I have to make Sub Category for CI's field visible only if there is a choice list available based on CI field. If a CI doesnt have a Sub Category for CI's choice associated, then the Sub Category for CI's should not be visible.
Ex" CI is Lync and Sub Category for CI's choice list is telephone, Voice - In this case, Sub Category for CI's should be visible
CI is Lync 2010 and Sub category for CI's is not having any choices - In this case, Sub Category for CI's should NOT be visible.
Can someone please guide me in achieving this. Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2015 02:45 AM
For demonstration, I have created a category "No Subcategory" with no dependent values.
onChange of the category field, wrote the below script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('SubCategoryExists');
ga.addParam('sysparm_name',"ifSubCategoryExists");
ga.addParam('sysparm_category',newValue);
ga.getXML(HelloWorldParse);
}
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if ( answer == "No Subcategory")
{
g_form.setDisplay("subcategory", false);
}
else
{
g_form.setDisplay("subcategory", true);
}
}
The corresponding script include is as below. Make sure to make it client callable.
var SubCategoryExists = Class.create();
SubCategoryExists.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ifSubCategoryExists: function() {
var iChoice = new GlideRecord('sys_choice');
iChoice.addEncodedQuery('name=incident^element=subcategory^dependent_value='+this.getParameter('sysparm_category'));
iChoice.query();
if(iChoice.next())
{
return "Subcategory Exists";
}
else
{
return "No Subcategory";
}
},
type: 'SubCategoryExists'
});
The client script is written on "onChange". You might want to extend it to the onLoad of the form as well.
I have tested this and it works. Let me know how it goes for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2015 02:08 AM
Hi,
did you try using a UI Policy?
In there you can use the Condition Builder to tell when the Action shall be executed.
And then use a Script or an Action to hide your Field..
In the Incident Table there should be an example which you can use.
It hides the SubCategory if the Category is 'Inquery/Help'.
If the Condition Builde can not help you try using a Script.
Regards,
René
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2015 06:28 AM
Hi Rene, Thanks for the input. I did use a client script but Im stuck in identifying whether a CI has a subcategory or not. I checked the demo instance as well as our instances and I noticed that the subcategory doesnt get hidden when you set the category as Inquiry/Help. Any help in identifying if a CI has a subcategory or not will be helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2015 01:17 AM
Hi,
you dont have to use a Script. That is one way of doing it.
I Provide a Screenshot there you can see that the SubCategory Field in the Incident Form will be hidden if the SubCategory in the CI is empty.
If you have trouble with your Script it would be helpfull to see what you already have as a Script.
Regards,
René
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2015 01:24 AM
Hi Rene
I guess Dot-walked fields cannot be used as conditions in condition filters.
Regards,
Srijanani