- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 03:30 AM
Hi All,
I have two variables in my record producer:
1. Customer(this is a reference field)
2.SOF(this is list collector)
I need to create a filter on the "SOF " field on the record producer form so that it only shows SOF records that are associated with the same Company that the record is for. So if the "Customer" field on the record producer form is set to "XYZ", then only SOF records where the "Company" field on the SOF record EQUALS "XYZ" should be displayed for the user to choose from.
Please let me know how I can achieve this.
Regards,
Shugufta.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2017 03:50 AM
Hi Shagufta,
Please use the updated code :
""
I advice to use an onChange client script which would set the filters to you. The list collector has to refer the right table for records. I had a catalog item where i have used this code,
I would request you to implement something similar(this is a catalog client script):
var collectorName = 'list_collector_field_name'; // the list collector field on the record producer
var filterString = 'group='+g_form.getValue(' field_name '); // from where the filter is dependent on the record producer
//Hide the list collector until we've set the filter
if(typeof(window[collectorName + 'g_filter']) == 'undefined'){
setTimeout(setCollectorFilter, 100); //Test if the g_filter property is defined on our list collector.
//If it hasn't rendered yet, wait 100ms and try again.
return;
}
window[collectorName + 'g_filter'].reset(); // this resets
window[collectorName + 'g_filter'].setQuery(filterString); //sets the filter
window[collectorName + 'acRequest'](null); //runs the filter automatically
once its populated it can fetched later in RITM and TASKs.
""
The default values of the list collector should not have no_filter , and as the client script does the task script include and calling script include can be excluded too.
Do reach back if you get struck.
Regards,
Shariq
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2019 12:22 PM
Hi Shariq,
I tried your code for a record producer I have where I want a reference field (select_cost_center) to filter a list collector (u_business_application). select_cost_center is only a variable and not passing a value to the produced record. u_business_application does; I'm not sure if this is the problem.
I want the filter to display "Bundled for Cost Centers" contains (value selected in select_cost_center variable). The field name is u_bundled_for_cost_centers and is also a list field on the cmdb_ci_business_app table. u_bundled_for_cost_centers and select_cost_center both reference the cmn_cost_center table.
Please have a look and let me know what I am doing wrong.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var collectorName = 'u_business_application'; // the list collector field on the record producer
var filterString = 'u_bundled_for_cost_centers='+g_form.getValue(‘select_cost_center’); // from where the filter is dependent on the record producer
//Hide the list collector until we've set the filter
if(typeof(window[collectorName + 'g_filter']) == 'undefined'){
setTimeout(setCollectorFilter, 100); //Test if the g_filter property is defined on our list collector.
//If it hasn't rendered yet, wait 100ms and try again.
return;
}
window[collectorName + 'g_filter'].reset(); // this resets
window[collectorName + 'g_filter'].setQuery(filterString); //sets the filter
window[collectorName + 'acRequest'](null); //runs the filter automatically
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2018 05:37 AM
Hi Sharique,
I tried this code and its working in my case, but I need to hide the list collector if it is empty. If there is some value in list collector to show as per the condition then only list collector should be available on form or else it should be hidden on form. Can you plz help me with this.
I am using this code in one of my catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2018 07:06 AM
Hi Shrija,
Based upon which block (available/selected) would you like to consider the empty list conditon?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2018 07:14 AM
Based on Available I would like to consider empty . If based on condition available side of list collector comes empty then list collector should not be visible on form and if available has some value to select then list collector should be visible on form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2018 08:41 AM
Hi,()
I would just modify my existing logic provided earlier.
In the client script after my script ends
var str= filterString.indexOf('=');
if (filterString.substring(str+1,str+2)== ''){ //check if the value after = to sign is empty
g_form.setMandatory('list_collector_field_name',false); // if the field is mandatory for some reasons
g_form.setVisible('list_collector_field_name',false);
}
But this should had been another question