- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 12:33 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 01:08 AM
Hello @Dee S
You can try advanced reference qualifier on 'Share code' reference field on Task table
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...
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 01:00 AM - edited 01-29-2024 01:01 AM
No having full visibility in your configs but roughly, you can have something like this.
javascript : '<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()
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 01:08 AM
Hello @Dee S
You can try advanced reference qualifier on 'Share code' reference field on Task table
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...
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 04:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 04:36 AM
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
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates