How to set values dynamically in variables

Rani11
Tera Expert

Hi All,

Just a small query.

I have Variable which is referring to custom table.

Custom Table :

find_real_file.png

 

Role Display is Reference variable and above "Test Table" is used for reference. So When i select US-Store in the "Role Display" it should show relevant "US"country related location in the "Location" variable. here if US-STORE (then it is US country store. If they select (NZ-Store) then its is News Zealand country store.

find_real_file.png

 

So i tried script include and reference qualifier like below. But whatever i tried that is static one. I just wants to change that to dynamic one as per above logic. 

 

Script Include :

getLocation: function(role_display) {
var gr=new GlideRecord('cmn_location');
return 'country=Australia^u_active=true';
},

Reference Qualifier :

javascript:new LocUtils().getLocation(current.variables.role_display)

Its working as expected. but if i have one store then it should be fine but i have many stores. So i just wanted to change this to dynamic one. can anyone help me on this?

 

Thanks in Advance!!!

 

1 ACCEPTED SOLUTION

Rani11
Tera Expert

I have created script include and called the script include in the reference variable using advance.It worked .

Thanks all for your support.

View solution in original post

11 REPLIES 11

Rani11
Tera Expert

Hi Sanjiv,

US-Store is Role in my custom table. You can see here. If that role selected in Role Display variable then in the Location variable it should show US country related location details(Location variable is referenced to cmn_location table) . Maybe my previous response would have confused you (sorry for that).

find_real_file.png

Hope this is clear.

Hi Rani,

do you have some field on cmn_location table which holds the role i.e. US-Store

if yes then directly you can have something like this in advanced ref qualifier and no script include needed

javascript: 'role_field=' + current.variables.role_display;

If you want to use script include then you need to query it like this

getLocation: function(role_display) {

var arr = [];
var gr=new GlideRecord('cmn_location');

gr.addQuery('role_field', role_display);

gr.query();

while(gr.next()){

arr.push(gr.sys_id.toString());

}
return 'sys_idIN' + arr.toString();
},

Regards
Ankur

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

Hi Ankur,

 

No .I dont't have US-Store in cmn_location table. Its only in my custom table.

Only this if i select Role Display : US-Store from my custom table then it should show US related location in Location variable.

In my script include somewhere i have to say to the system like if role display is "US-Store" then go and search for US country related record in cmn location table and show it in Location variable.

Something like this.

Role Display: Referenced to "Test Table"

Location : Referenced to "cmn_location" 

So when selection of Role Display, Location should populate like this. 

I hope its clear now.

Hi Rani,

So if you don't have any field on cmn_location table to hold the information how the query can be made?

Are you saying you want to search for the name i.e. US-Store in the name field of location table

Regards
Ankur

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

Hi Ankur, No , i dont want to search US-Store in location table. Just i wanted to query the US related location and show it in the variable . Ex) in location table Active =true and Country is US. So it will list some record.That record i wanted to show in the item Location variable. Sameway i have two more option. IN-Store,NZ-Store So i wanted to hard code in the script include like if IN-Store then assume its india store then show the india country related record from location table to Location variable.Like somewhere i have to tell the system to if IN- Store role selected show india included location in the Location variable... Maybe the Role name is confusing you...ex ,US- ITIL If ITIL role selected in Role Display variable then show Location variable drop down with US country included locations ...like if i have 3 location in the US Country..i would like to show those three in the drop down. .. Pls suggest if you some best way to do also.. i am happy try that as well.