The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Reference qualifier with cilent script

AnnamalaiS
Tera Contributor

I have cost center field (select lookup with reference to cost center table) and project category field (selectbox with manually entered values).

 

Cost center based on project category.

 

Example: scent (project category) has 3 cost center. It should only visible instead of showing the whole list.

 

I need reference qualifier with client script for this.

 

26 REPLIES 26

GlideFather
Tera Patron

Hi @AnnamalaiS 

as client script is front side and the data are in server side, you will need to call an ajax from the client script and get that information for you.

 

 

  • Client script calling ajax
  • Ajax must be client-callable
  • logics to return in script include called by that ajax.

 

You can get some inspiration in following:

 

Cheat sheet:

 

Let me know if this helped you solve your issue or to get you closer to the solution.

PS: you might refer to client script and catalog client script, it does the same thing just client script is for backend and catalog client script for portal/EC... 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Ankur Bawiskar
Tera Patron
Tera Patron

@AnnamalaiS 

client script can't be used to set reference qualifier.

You need to use the advanced ref qualifier on that field to filter the Cost Center based on drop down

what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

In cost center field

Reference qual
 

javascript:'sys_idIN' + new CostCenterMapping().getCostCentersForCategory(current.variables.project_category); 

Attributes

ref_qual_elements=project_category

client script :
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '')
        return;
    var ga = new GildeAjax('CostCenterMapping');
    ga.addParam('sysparm_name','GetCostCentersForCategory');
    ga.addParam('sysparm_category',newValue);
    ga.getXmlAnswer (function(answer)
    {
});
}

script include :

var CostCenterMapping = Class.create();
CostCenterMapping.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetCostCentersForCategory:function(){
var category = this.getparamter('sysparm_category');
var costCenters = [];
var gr = new GlideRecord('u_proj_category_costcenter_map');
gr.addquery('u_project_category',category);
gr.query();
while (gr.next()){
    costCenters.push(gr.getValue('u_cost_center_name').toString());
}
return costCenters.join(',');
    },
type: 'CostCenterMapping'
});

it is not working as expected.
please guide me to solve.
 



Hi @AnnamalaiS you have a typo in GlideAjax:

 

    var ga = new GildeAjax('CostCenterMapping');
———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */