Cost Center filter by Company & Company Code

lbless1
Giga Expert

I need to set a filter for the Cost Center field based on the Company in Company of the Contingent Worker field. IF the company in the Company of the Contingent Worker field has a Company Code of 1000 than only show Cost Centers with Company Code of 1000.

Here is what I have and it is not working. Thoughts?

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {

          return;

    }

var company = g_form.getReference('cwo_company_of_the_cwr', getCode);

company.addEncodedQuery("u_company_code=1000 ");

function getCode(company)

{

var a=cost_center.u_company_code ("1000");

g_form.setValue('cwo_cost_center',a);

}

}

Catalog Form:

Screen Shot 2017-10-23 at 8.25.13 AM.png

Company Table with Company Code Field

Screen Shot 2017-10-23 at 8.21.40 AM.png

Cost Code Table with Company Code Field

Screen Shot 2017-10-23 at 8.23.48 AM.png

3 REPLIES 3

Chuck Tomasi
Tera Patron

What you are looking for is not done with a client script. It is done with a mechanism called a reference qualifier. It is designed specifically to filter the results presented on a reference field. I recommend starting here:



Reference qualifiers



Also, I invite you to watch the Quick Tip on Episode 36 of TechNow. I talk about these specifically.



TechNow Episode List


Chandu Telu
Tera Guru
Tera Guru

Hi lbelessington,



you need to write a script in dynamic filter


find_real_file.png


How about this?



function getCompanyCode ( ) {


  var answer   = '';


  var includes   = current.variables.textmatch;


  var usr = new GlideRecord('sys_user');


  usr.addQuery('u_company_code','CONTAINS',1000);


  usr.query();


}


  while (usr.next()) {


      if (answer = 1000 ) {


          answer += (',' + company.name); }


      else {


          answer   = ('' + company.name); }


      }


  return 'sys_idIN' + answer; }


}