- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 01:04 AM
Hello
In a service catalog item, I would like to make a field mandatory (or not) depending on the requested for’s country.
The problem of course is when displaying the formular of the item, we don’t know yet who is the requested for so I decided to make it dependent of the logged in user’s country.
I want then to write a catalog UI policy in which I would do the test if logged in user is from Country France, then variable not mandatory. If from other country, then let the variable mandatory.
How can I get the logged in user’s country from my catalog UI policy ?
Is there another way to manage my topic ?
Regards
Vanessa Heux
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 01:52 AM
Hi Vanessa,
As Kalai said, you can use an onLoad/onChange Client script which should call a Script Include to get logged in user's information.
I got one similar requirement where I have wrote an onLoad Client Script and called a script include through it.
Refer below code which will help you.
Client Script : AJ Auto-Populate Requestors fields
Type : onLoad
Applies to : Variable set // this variable set contains variables which stores requestor's details.
Script :
function onLoad()
{
var ga = new GlideAjax("requestor_details");
ga.addParam("sysparm_name","requestor_info");
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var result = serverResponse.responseXML.getElementsByTagName("result");
var phone = result[0].getAttribute("phone");
var user = result[0].getAttribute("user");
var email = result[0].getAttribute("email");
var manager = result[0].getAttribute("manager");
var company = result[0].getAttribute("company");
var location = result[0].getAttribute("location");
//Populate variables
g_form.setValue('phone',phone);
g_form.setValue('requested_by',user);
g_form.setValue('email',email);
g_form.setValue('company',company);
g_form.setValue('location',location);
g_form.setValue('manager',manager);
g_form.setReadOnly('email',true);
g_form.setReadOnly('phone',true);
g_form.setReadOnly('requested_by',true);
g_form.setReadOnly('manager',true);
g_form.setReadOnly('company',true);
g_form.setReadOnly("phone_number",true);
}
}
Script Include : requestor_details
Client Callable : true
Script :
var requestor_details = Class.create();
requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
requestor_info: function() {
var result = this.newItem("result");
var logged_user = gs.getUserID();
var user_detail = new GlideRecord('sys_user');
user_detail.addQuery('sys_id',logged_user);
user_detail.query();
while(user_detail.next())
{
result.setAttribute("user",user_detail.sys_id);
result.setAttribute("phone", user_detail.phone);
result.setAttribute("email",user_detail.email);
result.setAttribute("company",user_detail.company);
result.setAttribute("manager",user_detail.manager);
result.setAttribute("location",user_detail.location.getDisplayValue());
}
},
type: 'requestor_details'
});
Mark if Correct/Helpful
Regards,
Ajay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 03:35 AM
Hi Vanessa can you check by adding some more fields and getting their values on your cat client script, might be the script include is not getting called.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 03:43 AM
Hi Vanessa,
If you don't wanna go with client script, Check with these steps.
I have created a new variable with name "Requestor Company" as below
and then configured variable, such that it takes default value of logged in user's country as below
Now as per your requirement if country is france., I wrote Ui Policy as below
and now you can make any other variables mandatory accordingly by Ui-Policy action., for example see below image.
So, I hope would be helpful.
Thanks & Regards,
Rupesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 05:52 AM
Thanks it finally worked with other fields and I noticed that the country was not well filled for the user of testing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 05:55 AM
Great!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 06:50 AM
Hi Vanessa,
If you don't wanna go with client script, Check with these steps.
I have created a new variable with name "Requestor Company" as below
and then configured variable, such that it takes default value of logged in user's country and given type specifications as below
Now as per your requirement if country is france., I wrote Ui Policy as below
and now you can make any other variables mandatory accordingly by Ui-Policy action., for example see below image.
So, I hope this would be helpful/correct.
Thanks & Regards,
Rupesh.