- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 12:17 AM
Hello,
I'm currently working on a record producer and I would like to add an alert that will deny submitting the request if the requester is from a certain country, like UK.
I have a variable on the form named 'caller_id"(reference to sys_user table) which contains the requester's details and by default the value is populated with the user currently logged in the instance.
I was thinking to add an onSubmit client script that will display an alert if you're from UK and it will not allow you to submit the request. Unfortunately my scripting knowledge is limited and I don't know exactly what I need to do. Any thoughts would be much appreciated.
Thanks,
Alex
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 12:52 AM
Hi Alexandru,
You need to create a script include first with client callable enabled.
Here is the script include code
--------
var LocationUtil = Class.create();
LocationUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isUserFromUK:function()
{
var requestor=this.getParameter('sysparm_user_id');
var gr=new GlideRecord('sys_user');
if(gr.get(requestor) && gr.location.country=='United Kingdom')
return true;
return false;
},
type: 'LocationUtil'
});
-----
You need to call that script include from the onsubmit client script. here is the code.
function onSubmit() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('LocationUtil');
ga.addParam('sysparm_name','isUserFromUK');
ga.addParam('sysparm_user_id',g_form.getValue('caller_id'));
ga.getXMLWait();
var answer=ga.getAnswer();
if(answer=='true')
{
alert("You cannot submit the request");
return false;
}
}
Hope that helps
Thanks
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 12:52 AM
Hi Alexandru,
You need to create a script include first with client callable enabled.
Here is the script include code
--------
var LocationUtil = Class.create();
LocationUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isUserFromUK:function()
{
var requestor=this.getParameter('sysparm_user_id');
var gr=new GlideRecord('sys_user');
if(gr.get(requestor) && gr.location.country=='United Kingdom')
return true;
return false;
},
type: 'LocationUtil'
});
-----
You need to call that script include from the onsubmit client script. here is the code.
function onSubmit() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('LocationUtil');
ga.addParam('sysparm_name','isUserFromUK');
ga.addParam('sysparm_user_id',g_form.getValue('caller_id'));
ga.getXMLWait();
var answer=ga.getAnswer();
if(answer=='true')
{
alert("You cannot submit the request");
return false;
}
}
Hope that helps
Thanks
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 01:03 AM
Hi Srini,
It works! One more question: If I want to deny multiple countries, not just UK, do I just need to add if(gr.get(requestor) && gr.location.country=='United Kingdom' || 'Sweden' || Germany) or do I need to change something else?
Thank you!
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 01:21 AM
Hi Alexandru,
You need to do something like this.
if(gr.get(requestor))
var country=gr.location.country;
if(country=='United Kingdom' || country=='Sweden' || country=='Germany')
{
return true;
}
Hope this helps
Mark this answer as helpful/correct if it does so.
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 01:48 AM
Sweet! Thanks!