set field based on logged in used country
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 05:22 AM
Hello,
i have a lookup variable which has country data (like: australia, england, china, etc),
i want to set these lookup values based on the logged in user country location.
example: if requested for country = (India IN), then the variable (what country is this requested for?) should be automatically selected as = India. I have attached a similar example. The variable : (what country is this requested for? ) has value which is coming from a lookup and it is currently on the custom table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 05:46 AM
@Anubhav Srivas1 : Write a onload client script to set the value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 06:44 AM
can you please help me with the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 10:29 PM
@Anubhav Srivas1 : you can do it in two ways
1. using the onLoad Client script or you can change your variable type from lookup to "reference" and set the values as :
Reference Table :
cmn_location
javascript: gs.getUser().getRecord().getValue('country');
2. You can write an onload client Script:
function onLoad() {
var countryCode; // country code
var user = g_user; // current logged-in user
var userLocationGR = new GlideRecord(‘cmn_location’); //Location [cmn_location] table
if (userLocationGR.get(user.location)) {
countryCode = userLocationGR.getValue(‘country’); // Get the country from the user’s location
// lookup variable’s name is ‘country_lookup’ change it according to your variable
var countryLookupVariable = g_form.getReference(‘country_lookup’, function(countryLookupVar) {
// Set the value for the lookup variable based on the country code
g_form.setValue(‘country_lookup’, countryCode, countryLookupVar.display_value);
});
}
}
Thanks
Achyut