- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2017 03:03 AM
Hi All,
I'm trying to write a client script that will show a particular set of choice list options depending on the company the current user belongs to. The users company doesn't seem to be available via g_user so do i'm thinking i have to use a Glide Ajax? if that's correct can anyone advise on how to write this? I just watched technow epsiode33 on this and, along with other sources i've come up with the below but it doesn't seem to be working, a lot of it is guesswork so i have no clue where i've gone wrong
Client Script:
function userCompany(company){
var ga = new GlideAjax('GetUserCompany');
ga.addParam('sysparm_name','getComp');
ga.addParam('sysparm_company',company);
ga.getXMLanswer();
alert(ga.getAnswer());
}
if(userCompany == 'Company Name Here'){
g_form.clearOptions/addOption..blah blah blah....
Script Include:
var GetUserCompany = Class.create();
GetUserCompany.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getComp: function() {
var comp = this.getParameter("sysparm_company");
return gs.getUser().getCompanyID(company);
}
});
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2017 03:15 AM
Hello David,
Client Script:
var ga = new GlideAjax('GetUserCompany');
ga.addParam('sysparm_name','getComp');
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer"); // answer will now have company sys id; if you want name of company. please do glide record company table to fetch the name of the company.
if(userCompany == 'Company sys id Here'){
g_form.clearOptions/addOption..blah blah blah....
}
Script Include:
var GetUserCompany = Class.create();
GetUserCompany.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getComp: function() {
return gs.getUser().getCompanyID(); //returns sys id of an company to client script as an answer
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2017 03:47 AM
Thanks Surya, if was the initial userCompany function call that was causing issues. I stuck with getXMLAnswer though as it negates the need to parse out the information using the response.responseXML.documentElement etc etc syntax.
Final client script:
var ga = new GlideAjax('GetUserCompany');
ga.addParam('sysparm_name','getComp');
ga.getXMLAnswer(returnComp);
function returnComp(response){
if(response == 'e3e0c843db6c7200e576b14ffe9619dc'){
g_form.clearOptions/addOption...blah...blah...blah
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2017 06:21 AM
Hello Dave,
If i answered your question, kindly mark my answer as correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2017 03:53 AM
David Dubuis wrote:
Hi All,
I'm trying to write a client script...
.. does it need to be a client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2017 03:59 AM
So, the eventual goal is to have different views set up to partition off various different companies within the group. Once these views are in place the choice list options will be defined on that basis.
This is basically just a bit of a workaround until our professional services guys have done the business with the views. It's also a handy excuse to start getting to grips with GlideAjax records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2017 05:48 AM
David Dubuis wrote:
This is basically just a bit of a workaround until our professional services guys have done the business with the views. It's also a handy excuse to start getting to grips with GlideAjax records.
That is definitely is!
Yeah, if you've got a "proper" way and this is just a temporary filler, I'd say go for it.