Passing sys_id into on demand script include

y-allen
Tera Contributor

Okay. I am trying to add two reference qualifiers to two fields on a custom SN table. I wrote two on demand script includes using GlideQuery to obtain the sys_ids from those tables and push them into an array. I have confirmed using background scripts that the script includes are, indeed, pulling the records I want them to pull and push into the array. So with the fields not displaying the correct, or in some cases any, records when i click to search means that there is an issue with the code i am using to call the function. I suspect that i am not passing in the sys_id for the current record into the script include when called, but i am not seeing a way to test that.

 

Both fields are on a form that has an associated ID, which is a reference field. When someone updates the record and clicks on field A, I only want them to be presented with records associated with that same ID from the secondary table. The ID field is also a reference field on the second table.

 

Right now, this is what I have in the ref qual field in the field properties

javascript: 'sys_idIN' new script_include_name(current.sys_id);

 

I have tried countless other variations and even reviewed what others have done for previous ref quals. It appears no one has done specifically what I am trying to do nor has any of their examples worked.

 

Any assistance is appreciated and thanks in advance!

 

6 REPLIES 6

Brian Lancaster
Tera Sage

In your refence qualifier you should just have javascirpt: new script_include_name.function(current.sys_id).

In your script include it should be return "sys_idIN"+id.join(); in this example id is the array built in the script include.

Jim Coyne
Kilo Patron

Can you show us the Script Include you have?  At least the part where you are passing back the information.  Do you have some log statements to show that you are in fact getting the sys_id passed in as the parameter?

 

At the very least, your Reference qualifier should be:

javascript: "sys_idIN" + new script_include_name(current.sys_id);

...where you are missing the "+".  And I'm assuming you are replacing "script_include_name" with the actual name.

 

Have you tried without the "new" keyword?  Not sure if on-demand Script Includes need/use it????

 

And I prefer to send the "sys_idIN" part back as part of the return value as well so that you get the entire string back from the Script Include.  I find it cleaner, because in some instances, in some Reference Qualifiers, you may be sending back different conditions.  But that's just a preference.

y-allen
Tera Contributor

Thank you for the response gentlemen. Unfortunately, I got two different results from the recommendations you provided:

Reference Qual:

javascirpt: new refQualMatchingIsas(current.sys_id)

 

Script Include:

function refQualMatchingIsas(proj) {

var isas = [];


new global.GlideQuery('table_name')
.where('project_id.sys_id', proj)
.select('sys_id')
.forEach(function(e) {
isas.push(e.sys_id);
});
return isas;
}

 

Result: All records returned.

 

Reference Qual:

javascript: "sys_idIN" + refQualMatchingIsas(current.sys_id);

 

Script Include:

function refQualMatchingIsas(proj) {

var isas = [];


new global.GlideQuery('table_name')
.where('project_id.sys_id', proj)
.select('sys_id')
.forEach(function(e) {
isas.push(e.sys_id);
});

return "sys_idIN" + isas.join();
}

 

Result: No records returned.

 

Also I have no indication that sys_id is getting passed in. My assumption is that its not due to an incorrect calling of the function.

Without knowing if the parameter is correct or not, you look to be close.

 

For the second example, the Reference Qualifier should be:

 

javascript: refQualMatchingIsas(current.sys_id);

 

Because you are including the "sys_idIN" string in the return from the function, you would end up with "sys_idINsys_idIN" + the sys_ids, which would be invalid.  Both examples would have worked, I think, if you switched the Reference Qualifiers around (without the "new").