Call two script include in one Client Script?

zrocky
Giga Contributor

Hello SN Community,

Is it possible to call two script include, compare their values, and if they match auto-populate a field?

1st Script Include

function getCostCenter(record) {

  var ccListProperty = gs.getProperty('aitqa_cost_centers');

  var ccArr = ccListProperty.split(',');

  var result = '';

  var gr = new GlideRecord('sys_user');

  gr.addQuery('sys_id', current.u_resource_manager);

  gr.query();

  while (gr.next()){

  if (gr.u_sector == 'Ann-Quality Assurance') {

  var qacc;

  for (i=0; i<ccArr.length;i++) {

  qacc = new GlideRecord('cmn_cost_center');

  qacc.addQuery('name', ccArr[i]);

  qacc.query();

  while (qacc.next()) {

  result += qacc.sys_id + ',';

  }

  }

  }

  result += gr.cost_center + ',';

  }

  return 'sys_idIN' + result;

}

2nd Script Include

function getCostCenter(record) {

  var ccListProperty = gs.getProperty('aitqa_cost_centers');

  var ccArr = ccListProperty.split(',');

  var result = '';

  var gr = new GlideRecord('sys_user');

  gr.addQuery('sys_id', current.u_resource_manager);

  gr.query();

  while (gr.next()){

  if (gr.u_sector == 'Ann-Quality Assurance') {

  var qacc;

  for (i=0; i<ccArr.length;i++) {

  qacc = new GlideRecord('cmn_cost_center');

  qacc.addQuery('name', ccArr[i]);

  qacc.query();

  while (qacc.next()) {

  result += qacc.sys_id + ',';

  }

  }

  }

  result += gr.cost_center + ',';

  }

  return 'sys_idIN' + result;

}

I would like to write a Client Script where I can call these two Script Includes, execute, match their fields (Cost Center Code needs to match with CCOwner, i.e. 123345 == John Doe) and if they match. Auto-populate Cost Center Owner field on a form.

8 REPLIES 8

Sashi K1
Kilo Guru

Think about using a Display Business Rule during form load. That could efficiently make Server calls, keep answer available to the client script.


Calling script includes from a client scripts would take more load. Rather keep answer ready to client script using a Display Business Rule. During form, load BR would execute above logic, keep cost center to auto populate.


Srinivas Balusu
Kilo Guru

Technically - Yes, you can call two script include from a client script.



But it might have a performance impact. And from the above script includes which you shared you are returning a list of values. I am not sure if there is a possibility in your case / I am unsure what you are trying to achieve.


mitchellstutler
Tera Contributor

One option is to create a new script include that handles all of the calculations and then returns any values necessary.



Also, I almost always make calls from client scripts to script includes with a GlideAjax call.


Madhava_Kumar
Mega Guru

Hi Rocky,



You can call two script include in a client script, looking at your functions, you might get many records and then you need to do the for loop thing, it takes more time for executing. After that when you get the result again you need to compare the result in client script, as shashikanth said better to use a Business Rule.



thanks


Madhava