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

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

Hi, Thanks for observing the missing parenthesis. There was one more issue with it though, extra space between 'javascript' and ':' . it worked now 🙂

ABHISHEK105
Tera Contributor

I Found one more issue along with the syntax error explain by other community member.

var gr1 = new GlideRecord('sys_user');
gr1.addQuery('user_name',storeNo);
gr1.query();

 

in gr1.addQuery('user_name',storeNo); ,you are trying to find a member from user table which can be matched with store number, this will return nothing, Also please try this separately in script background if this works.