How to Send table name & query dynamically to script include?

Nani9
Tera Contributor

How to Send table name & query dynamically to script include?, so i will get list of records.

~Thanks

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, unfortunately your question\requirement is not very clear.
You can pass values between scripts using parameters and the table name is the 'sys_class_name' field of a record. this is a basic example which you should be able to run in a background window of a PDI.
The behaviour is exactly the same for a script-include function call.

//simple function with 2 parameters
function testFunction(Table, Query) {
var gr = new GlideRecord(Table);
gr.addEncodedQuery(Query);
gr.query();
if(gr.next()) {
gs.info("myParent record via function " + gr.number);
}
}

//create a variable called current for testing using OOB record from a PDI
var current = new GlideRecord('incident');
current.get('ff4c21c4735123002728660c4cf6a758');

gs.info("Current record " + current.number);
//set 2 variables based on the current record
var myQuery = 'parent_incident=' + current.parent_incident.sys_id + '^';
var myTable = current.sys_class_name;

//pass these variables to the function as parameters
var myResult = testFunction(myTable, myQuery);

View solution in original post

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, unfortunately your question\requirement is not very clear.
You can pass values between scripts using parameters and the table name is the 'sys_class_name' field of a record. this is a basic example which you should be able to run in a background window of a PDI.
The behaviour is exactly the same for a script-include function call.

//simple function with 2 parameters
function testFunction(Table, Query) {
var gr = new GlideRecord(Table);
gr.addEncodedQuery(Query);
gr.query();
if(gr.next()) {
gs.info("myParent record via function " + gr.number);
}
}

//create a variable called current for testing using OOB record from a PDI
var current = new GlideRecord('incident');
current.get('ff4c21c4735123002728660c4cf6a758');

gs.info("Current record " + current.number);
//set 2 variables based on the current record
var myQuery = 'parent_incident=' + current.parent_incident.sys_id + '^';
var myTable = current.sys_class_name;

//pass these variables to the function as parameters
var myResult = testFunction(myTable, myQuery);