- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 01:53 AM
I would like to add a the country flag to the country field on the sys_user table, for example if the country is united kingdom then I will see the UK flag next to the field. Is there a way to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 04:54 AM
@Jake Sadler mean while I tried this in my instance, let me present you the steps I followed,
- Download all the flags from any source you prefer and preferably the size of the image should be 14 px X 14 px and PNG format.
- Rename all the images to a standard format like <2 Letter Country Code>.png [For example, IN.png, US.png, FI.png etc.]
- Upload all the images to ServiceNow at System Ui -> Images
- Click on New in the List view
- In the page opened, select some category and in the name field fill in the name in same format as we followed above and then click on Click to add.. link next to image and upload your flag and click OK
- Then you will be brought back to the Image properties page, click on Update button to save the image.
onLoad Client Script: Create an OnLoad client script like with the following script on sys_user table.
Note: Do not forget to un check the Isolate Script check box, if the field is not available on the client script form add it to the form from Form layout configuration.
function onLoad() {
var country = g_form.getValue('country');
if(country === ''){
return;
}
var flag = country + '.png';
var countryLabel = $('element.sys_user.country');
countryLabel.setStyle({
backgroundImage: "url("+ flag +")",
backgroundPosition: "80% 55%",
backgroundRepeat: "no-repeat"});
}
OnChange Client Script: Create an OnChange client script like with the following script on sys_user table for Country Code field.
Note: Do not forget to un check the Isolate Script check box, if the field is not available on the client script form add it to the form from Form layout configuration.
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue === ''){
return;
}
var flag = newValue + '.png';
var countryLabel = $('element.sys_user.country');
countryLabel.setStyle({
backgroundImage: "url("+ flag +")",
backgroundPosition: "80% 55%",
backgroundRepeat: "no-repeat"});
}
And the result is,
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 03:43 AM
Hi @Jake Sadler
Have you checked this KB Article from ServiceNow?
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0752116
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 04:54 AM
@Jake Sadler mean while I tried this in my instance, let me present you the steps I followed,
- Download all the flags from any source you prefer and preferably the size of the image should be 14 px X 14 px and PNG format.
- Rename all the images to a standard format like <2 Letter Country Code>.png [For example, IN.png, US.png, FI.png etc.]
- Upload all the images to ServiceNow at System Ui -> Images
- Click on New in the List view
- In the page opened, select some category and in the name field fill in the name in same format as we followed above and then click on Click to add.. link next to image and upload your flag and click OK
- Then you will be brought back to the Image properties page, click on Update button to save the image.
onLoad Client Script: Create an OnLoad client script like with the following script on sys_user table.
Note: Do not forget to un check the Isolate Script check box, if the field is not available on the client script form add it to the form from Form layout configuration.
function onLoad() {
var country = g_form.getValue('country');
if(country === ''){
return;
}
var flag = country + '.png';
var countryLabel = $('element.sys_user.country');
countryLabel.setStyle({
backgroundImage: "url("+ flag +")",
backgroundPosition: "80% 55%",
backgroundRepeat: "no-repeat"});
}
OnChange Client Script: Create an OnChange client script like with the following script on sys_user table for Country Code field.
Note: Do not forget to un check the Isolate Script check box, if the field is not available on the client script form add it to the form from Form layout configuration.
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue === ''){
return;
}
var flag = newValue + '.png';
var countryLabel = $('element.sys_user.country');
countryLabel.setStyle({
backgroundImage: "url("+ flag +")",
backgroundPosition: "80% 55%",
backgroundRepeat: "no-repeat"});
}
And the result is,
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh