- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 09:13 AM
How to Send table name & query dynamically to script include?, so i will get list of records.
~Thanks
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 09:15 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 09:15 PM
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);