Adding filter of custom table's filed to target table

Tamil4
Tera Contributor

Hi Everyone!

 

Am having a custom table, in that I have a field called condition which is Conditions type field.

I have to get the value of this condition filed and use that as a filter in my target table through script.

 

For Example: The custom table's condition field having company=ACME Africa, then I should use the same in incident table filter.

Tamil4_0-1681811793933.png

 

Below is the script I wrote. Not sure how far it is correct.

 

1. var Script = new GlideRecord('u_integration_configuration'); -> this is the custom table name

2. Script.addQuery('u_table_name', current.sys_class_name);
3. Script.addQuery('u_active', true);
4. Script.query();
5. while (Script.next()) {
6. //var fliterString = Script.getValue('u_condition');
7. var Rec = new GlideRecord(Script.u_table_name);
8. Rec.addEncodedQuery(Script.u_condition);
9. Rec.query();
10. if (Rec.next()) {

 

In the 8th line I have to use the condition field's value of custom table.

 

Please help me to achieve this.

 

Thanks in advance.

 

Thanks,

Tamil

19 REPLIES 19

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Why don't you go to the table(table name.list) and apply the filter and just copy that (Right click on the filter and Copy Query)

And use that query on line 8 

-Anurag

Tamil4
Tera Contributor

Thank you Anurag for your immediate response.

 

Actually it should take dynamic values at times. So I can't paste the copied query. Like If I have another record in my custom table and that is having different filter condition (not same as Company=ACME Africa) so then I should pass that condition to the target table.

 

Tamil

You should not use keywords and reserved words as variables

 

Try this

 var sc = new GlideRecord('u_integration_configuration'); -> this is the custom table name
sc.addQuery('u_table_name', current.sys_class_name);
sc.addQuery('u_active', true);
sc.query();
while (sc.next()) {

var rec = new GlideRecord(sc.u_table_name);
rec.addEncodedQuery(''+sc.u_condition);
rec.query();
if (rec.next()) {
//do whatever
}
}
-Anurag

Changed the keyword but still it is not working.

 

Tamil