Call Script include from Reference Qualifier

amitgaur
Tera Contributor

I have a catalog item which has 2 variables 'requested_for' and 'store_no'. Both are reference fields. 'requested_for' is auto populated with logged in user details, it can be changed too. Based on 'requested_for' the 'store_no' field should show only the stores listed for that user. so basically a reference qualifier is needed here. Although it is quite simple, but for some reason my reference qualifier is not able to call the script include(i checked it using script log statements). I have tried all possible ways. Can anyone suggest? Below is the code.

Also, I need to pass the current form 'requested'for' field value(which would be sys_id of user due to reference field) to script include, which i am trying to do in reference qualifier by trying to pass value. I am not even able to call the script include and get to the first log statement "Script Include called " . I am sure there would be something very simple that i am missing 😞

reference qualifier filed of 'store_no' : javascript : new x_infte_esm_itemde.MIP_StoreInfo.getStoreIDs(current.variables.requested_for);

Script Include Name : MIP_StoreInfo

API Name : x_infte_esm_itemde.MIP_StoreInfo

Client Callable : true

Accessible from : All applications scope

Code :

 

var MIP_StoreInfo = Class.create();
MIP_StoreInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

getStoreIDs: function(a){

gs.log("Script Include called ");
var user = a;
var storeID = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',user);
gr.query();
if(gr.next())
{
var allowedStore = gr.u_allowed_stores;
gs.log("Script Include found stores "+ allowedStore);
if(allowedStore != ''){
var storeNo = allowedStore.split(",");
for(i = 0; i < storeNo.length; i++){
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('user_name',storeNo);
gr1.query();
while(gr1.next()){
storeID.push = gr1.sys_id;
}
}
}
}
return 'sys_idIN' +storeID;

},
type: 'MIP_StoreInfo'
});

1 ACCEPTED SOLUTION

Sebastian L
Mega Sage

It seems you are missing the () after the first function call. So it should be: 

 

javascript : new x_infte_esm_itemde.MIP_StoreInfo().getStoreIDs(current.variables.requested_for);


Best regards,
Sebastian Laursen

View solution in original post

12 REPLIES 12

Mark Roethof
Tera Patron
Tera Patron

Hi there,

This looks like a scoped app? Is that correct? If so: gs.log will not work. Try gs.info instead.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

I've found this old slide from 2015 about using debug messages. Amongst them gs.log, will still work in global, though not in scope (also in global, try to make habit of not using gs.log).

If scoped, you probably also get an error message in the system log like "com.glide.script.fencing.MethodNotAllowedException: Function log is not allowed in scope *. Use gs.debug() or gs.info() instead"

find_real_file.png

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Thanks Mark, But even gs.info didn't work. The script include is not getting called from reference qualifier. I am not getting the issue with it.

Ah oke, so it's how the script include is called already.

I just copied/paste your reference qual. I noticed there's a space at the beginning.

javascript : new x_infte_esm_itemde.MIP_StoreInfo.getStoreIDs(current.variables.requested_for);

This will be an issue.

Change it at least into:

javascript: new x_infte_esm_itemde.MIP_StoreInfo.getStoreIDs(current.variables.requested_for);

or

javascript: new x_infte_esm_itemde.MIP_StoreInfo().getStoreIDs(current.variables.requested_for);

So the space between javascript and :

and maybe the MIP_StoreInfo()

See if it's called then, if it works or that the expected info messages are written to the system log or that you are getting system log messages like "java.lang.SecurityException: Illegal access to private script include MIP_StoreInfo in scope * being called from scope global".

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn