- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2016 08:48 AM
I have added an info message via 2 separate Catalog UI policys as follows;
Conditions
Member Firm | Is | London
and
confirm_policy | is | No
Selected Advanced and selected the Run Script checkbox
Script
function onCondition() {{return g_form.addErrorMessage('Please confirm you have read the Global cyber security and information assurance policy. Select Yes to confirm.');}}
I then created another UI policy for french users
Conditions
Member firm | is France
And
confirm_policy | No
function onCondition() {return g_form.addErrorMessage('Veuillez confirmer que vous avez lu la Politique sur la cybersécurité. Sélectionnez Oui pour confirmer. ');}
When I test as a London user and Select no, the message appears as expected (GREAT!)
The same with a French user and it shows the french message (GREAT!
PROBLEM
When selecting a French/London user where the location is France and testing it. It gives the French Message instead of English.
What we want is that
- French London users show a English message
- French users show a french message
- London Users show and English message.
Can anyone suggest a script change that will work on the UI Policy.
Much apreaciated in advance!
Sarah
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 07:31 AM
Thanks so much Chuck,
I have just changed it to 'No' and it's working now for English, French and French/English users.
Final script (working as expected)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var cyber_policy = g_form.getValue('cyber_policy');
if (isLoading || cyber_policy == '') {
return;
}
if (cyber_policy == 'No') {
g_form.addErrorMessage(getMessage('cyber_policy'));
}
}
Thanks so much for all your help on this Chuck. Really appreciate it!
Regards
Sarah

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2016 08:56 AM
I recommend a simpler approach...
Create a generic client script to just show the message on condition. Use a "key" in your message (and ensure this key is in the Messages field of your client script.)
e.g. g_form.addErrorMessage(getMessage('confirm_policy'));
Now use the System UI> Messages records to keep a an English and French version of the message that corresponds to the key.
key: confirm_policy
Language: English
Message: (what you want to say in English)
key: confirm_policy
Language: French
Message: What you want to say in French
It will display the proper message based on the user's language setting in their profile, not the location. Let the user decide their language preferences and it keeps you out of the weeds of when to display what.
http://wiki.servicenow.com/index.php?title=Language_Internationalization
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 04:37 AM
Hi Chuck,
Thanks for the reply, it's very helpful. I knew there had to be an easier way…..
The only problem I have is writing the condition for the Client Script, my scripting skills are at the "toddler stage", and I seem to be learning as I go along. I am fascinated and keen to learn more but, it will take me some time to get up to speed where scripting is concerned.
On the UI Policy you can add the condition using the buttons, but the buttons are not there on the client script form and I cannot see a related list to add.
I have managed to do the other parts you mentioned, but without the condition, I can't test it to see if it worked.
Are you able to advise how to write the condition for confirm_policy yes/ no field = no as part of the client script?
So far my client script is as follows:
Name: Confirm Policy
Applies to: A Catalog Item
Type: OnChange
Catalog Item: Printer installation
Variable name: confirm_policy
Messages: confirm_policy
Script: Might be totally wrong but I thought I would try. ☺
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || 'cyber_policy' == '') {
return;
}
else ('cyber_policy' == 'false') {
g_form.addErrorMessage(getMessage('confirm_policy'));
}
}
Much appreciated in advance.
Kind regards
Sarah

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 05:30 AM
Hi Sarah,
I think you're close. You just need to determine what "cyber_policy" is. It looks like you are trying to compare the value of the Cyber Policy (cyber_policy) variable. In which case I would suggest something like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var cyber_policy = g_form.getValue('cyber_policy');
if (isLoading || cyber_policy == '') {
return;
}
if (cyber_policy == 'false') {
g_form.addErrorMessage(getMessage('confirm_policy'));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 06:16 AM
Thanks for this Chuck,
I have just amended as per your comments and I understand…(I think that I didn't create a var. When I test the catalog item and select No the messages do not show at all. For both English or French users.
Updated client script
Variable name: cyber_policy
Message: cyber_policy
Updated Script (thanks)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var cyber_policy = g_form.getValue('cyber_policy');
if (isLoading || cyber_policy == '') {
return;
}
if (cyber_policy == 'false') {
g_form.addErrorMessage(getMessage('cyber_policy')); //Also kept it as confirm_policy but this did not work either.
}
}
Messages created in the System UI > Messages table
Message created for English
Key : cyber_policy
Language: English
Message: Please confirm that you have read the policy on cyber security, Select Yes to confirm.
Message created for French
Key : cyber_policy
Language: French/Canada
Message: Veuillez confirmer que vous avez lu la Politique sur la cybersécurité. Sélectionnez Oui pour confirmer.
Language plugin for French Canada is enabled in the instance.
Any ideas?
Kind Regards
Sarah