Reference qualifier to show share code from task which is related to logged in user's country code

Dee S
Giga Guru

Hi,

 

Task table has custom field 'share code' referring to 'Country share code' table which is a custom table

User table has custom code 'country code' which is string

both country code and share code shares same value like AUS, PHP, IND, UK, USA

One Task will have one share code where one user can have many country codes.

 

Requirement:

The share code field (reference) should only show logged in users country code on Task form. If user is having 2 country codes then user should only see 2 country codes in that reference field.

I'm thinking to add reference qualifier & create script include for share code field (reference).

 

Please help in creating reference qualifier and script include

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hello @Dee S 

 

You can try advanced reference qualifier on 'Share code' reference field on Task table

 

VishalBirajdar_0-1706519276177.png

 

 

javascript: 
var query;
var codes;
var user = gs.getUserID();    //get logged in User   

/*Glide record on user table*/
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',user);
gr.query();
if(gr.next()){
   codes = gr.getValue('u_country_code');
}
query='u_codeIN' +codes;

/*Here,
u_code  = Code name field present on custom 'Country share code' table  may be different for you*/

 

 

**You can use this script script include function & call that in reference qualifier... 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

4 REPLIES 4

Sonam_Tiwari
Kilo Sage

No having full visibility in your configs but roughly, you can have something like this.

 

javascript &colon; '<field_name for share code on custom table>IN'+new ScriptIncludeName().getCustomCode(user)

 

In your script include

 

 

 

 

 getCustomCode: function(value){ //value is user passed from ref qualifier for which you want to pull country codes - assuming they are comma seperated in your string field as you said there can be many mapped to one user.


Make your Glide
Filter with user
pull country codes

return arr_codes.toString()

},

 

 

 

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

Vishal Birajdar
Giga Sage

Hello @Dee S 

 

You can try advanced reference qualifier on 'Share code' reference field on Task table

 

VishalBirajdar_0-1706519276177.png

 

 

javascript&colon; 
var query;
var codes;
var user = gs.getUserID();    //get logged in User   

/*Glide record on user table*/
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',user);
gr.query();
if(gr.next()){
   codes = gr.getValue('u_country_code');
}
query='u_codeIN' +codes;

/*Here,
u_code  = Code name field present on custom 'Country share code' table  may be different for you*/

 

 

**You can use this script script include function & call that in reference qualifier... 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi Vishal,

the above should be in script include or Reference qualifier (Advanced). I believe it is script include but I can see you've written it on Ref qualifier.

Could you please confirm

Hi @Dee S 

 

Both will work....

You can write script in reference qualifier also......this will work....

 

But its general practice to write code in script include & then call that script include in reference qualifier

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates