- 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 06:21 AM
The subcategory field is dependent to CI field rite so in the client script you can query that before making the subcategory field visible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2015 06:30 AM
Yes, subcategory field is dependent to CI. How do I query. Can you give me the script plz?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2015 06:46 AM
Hi,
You need to query the subcategory choice list with the column name"dependant value".. Since the subcategory is dependent field. say example there is "inquiry" as dependent value in subcategory choice list. If the query returns nothing you can hide the field.
Regards,
Srijanani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2015 06:58 AM
Hi catch dini,
You can write onChange GlideAjax call to query sys_choice table with dependent value and fetch its record, if the value is vailable than return true flag else return false flag. in case of false flag in client script make the field visibility false.
Server side code:
var ciName=this.getParameter('sysparm_ciname');
var returnValue='false';
var gr=new GlideRecord('sys_choice');
gr.addQuery('dependent_value',ciName);
gr.query();
if(gr.next())
{
returnValue='true';
}
return returnValue;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2015 02:17 AM
Thanks Pradeep. Will try that code and let you know.