Field and form rules to filter custom field based on Site

Field and form rules to filter custom field based on Site

After reading the following forum post regarding Field and Form rules filtering I've decided to give this a go on my requester form

https://forums.manageengine.com/topic/field-form-rules-filtering-list-of-picklist-values

I'm trying to filter the results of my custom field named Location (WorkOrder_Fields_UDF_CHAR90) by what is selected from the Site field

Example- If someone selects 'Reading' from the Site field i only want options in the Location field to display if they contain the word Reading (Example location- Civic (Reading)).

This is my script based on the one in the referenced forum post

var Site_ele = jQuery('[data-field=SITE]'); // Getting Site Element
var Location_ele = jQuery('[data-field=WorkOrder_Fields_UDF_CHAR90]'); // Getting Location Element

filter_Site_Location_values(); // Executing the Script on Form Load

Site_ele.bind('change',function(){ 
   Location_ele.val('0'); // Setting the Location Element Value to default one
   filter_Site_Location_values();// Executing the Script on Site Element Changes 
});

function filter_Site_Location_values(){
   var Site_val = Site_ele.val();
   var Location_val = Location_ele.val();
 
   if(Site_val === '0'){
      Location_ele.find('option').hide(); //Hiding all Locations if the Site value is empty
   }else{
     Site_val = $CS.getText("SITE");
          
      Location_ele.find('option').each(function(){ // Show and hide elements of Site
         var prj_val = jQuery(this).attr('value');
               
         if(prj_val.indexOf(Site_val) == -1 && prj_val != '0'){  // Checking the Location options with Site Value. 
           //jQuery(this).hide();
           
           window.alert("Hiding: " + prj_val);                                 
           
           //$CS.hideOptions("WorkOrder_Fields_UDF_CHAR90", [prj_val]);
         }else{
            jQuery(this).show();
         }
      });
   }

A very similar request is raised and answered in the referenced forum post , which I have tried but it hasn't worked (See below). I have tried to amend this and put popup boxes in place to give me some feedback as to what it's doing. Sadly, though it does appear to try and hide the fields when I select a site it fails to do so and I'm unsure why.

Help!

As we add Clients and Projects, I don't want to have to update the script.

So since our values are setup as:
- Client has the following values: Acme, TNT, Beep Beep
- Project has the following value: Cliff (Beep Beep), Glue (Acme), Rocket (Acme), Large Box (TNT), Rubber Band (Acme)

Once a user choose Client = Acme, then Project will display only the values that contain "(<client value>)" (e. g. "Glue (Acme)", "Rocket (Acme)" and "Rubber Band (Acme)".

If we add a new Project called "Rock (Acme)", the script would automatically bring it in without having to modify it.
Siddik Employee
Hi Kevin,


Please replace the existing script with the below one. 

  1. var client_ele = jQuery('[data-field=WorkOrder_Fields_UDF_CHAR18]'); // Getting Client Element
  2. var project_ele = jQuery('[data-field=WorkOrder_Fields_UDF_CHAR19]'); // Getting Project Element

  3. filter_client_project_values(); // Executing the Script on Form Load

  4. client_ele.bind('change',function(){ 
  5.    project_ele.val('0'); // Setting the Project Element Value to default one
  6.    filter_client_project_values();// Executing the Script on Client Element Changes

  7. });

  8. function filter_client_project_values(){
  9.    var client_val = client_ele.val();
  10.    var project_val = project_ele.val();

  11.    if(client_val === '0'){
  12.       project_ele.find('option').hide(); //Hiding all projects if the Client value is empty
  13.    }else{
  14.       project_ele.find('option').each(function(){ // Show and hide elements of Clients
  15.          var prj_val = jQuery(this).attr('value');
  16.          if(prj_val.indexOf(client_val) == -1 && prj_val != '0'){  // Checking the project options with Client Value. 
  17.             jQuery(this).hide();
  18.          }else{
  19.             jQuery(this).show();
  20.          }
  21.       });
  22.    }
  23. }   

                  New to ADSelfService Plus?