Relationship with script to query multiple fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2024 12:37 PM - edited ‎02-12-2024 03:06 PM
I have created a relationship between 2 tables where I need to determine a match of at least one field in the parent child to at least one in the child. For example; Look for a match parent field 1 with at least one of the 4 child fields, repeat this process for all 4 parent fields. I have optimized the query so that when a hit is found the remainder of the matching logic is bypassed, and have added further logic to only process children records created in the last year. The parent consists of the one record and the child table conatains approximately 60,000 - with the date constraint it is taking around 45 seconds to process
To further clarify, this is in a relationship , it successfully returns the information that I am after with the query as developed. The issue is the query runs over 5 minutes and it is preventing the form from opening for that amount of time. So the issue is from an optimization standpoint and since there are only approx. 60,000 entries in the table the query should return the results much quicker
var gr5 = new GlideRecord('child table');
gr5.addQuery('entity', 'quote');
gr5.addQuery('sys_created_on', ">", gs.yearsAgo(1));
gr5.query();
while (gr5.next()) {
if ((parent.u_key_client_id != ' ') && !extmquote) {
if ((gr5.key_client_id == parent.u_key_client_id) ||
(gr5.client_id_2 == parent.u_key_client_id) ||
(gr5.client_id_3 == parent.u_key_client_id) ||
(gr5.client_id_4 == parent.u_key_client_id)) {
extmquote = true;
tskIDArr.push(gr5.sys_id.toString());
}
}
if ((parent.u_client_id_2 != ' ') && !extmquote) {
if ((gr5.key_client_id == parent.u_client_id_2) ||
(gr5.client_id_2 == parent.u_client_id_2) ||
(gr5.client_id_3 == parent.u_client_id_2) ||
(gr5.client_id_4 == parent.u_client_id_2)) {
extmquote = true;
tskIDArr.push(gr5.sys_id.toString());
}
}
if ((parent.u_client_id_3 != ' ') && !extmquote) {
if ((gr5.key_client_id == parent.u_client_id_3) ||
(gr5.client_id_2 == parent.u_client_id_3) ||
(gr5.client_id_3 == parent.u_client_id_3) ||
(gr5.client_id_4 == parent.u_client_id_3)) {
extmquote = true;
tskIDArr.push(gr5.sys_id.toString());
}
}
if ((parent.u_client_id_4 != ' ') && !extmquote) {
if ((gr5.key_client_id == parent.u_client_id_4) ||
(gr5.client_id_2 == parent.u_client_id_4) ||
(gr5.client_id_3 == parent.u_client_id_4) ||
(gr5.client_id_4 == parent.u_client_id_4)) {
extmquote = true;
tskIDArr.push(gr5.sys_id.toString());
}
}
if ((parent.u_name_insured != ' ') && !extmquote) {
if (gr5.name_insured_full_1 == parent.u_name_insured) {
extmquote = true;
tskIDArr.push(gr5.sys_id.toString());
}
}
}
var tskIDStr = tskIDArr.join();
current.addQuery('sys_id', 'IN', tskIDStr);
current.addQuery('sys_id', '!=', parent.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2024 02:41 PM
Hi, unfortunately your post does not make your requirement\intentions clear, or your issue\problem clear,
and your code appears incomplete\partial.
What are you trying to achieve\what is the use case for the results of your script?
Perhaps you gain efficiencies by generating an array (or multiple arrays) of sys_id's by querying the smaller 'parent' table, and then use the results in a query of the child table to include or exclude records as required IE sys_idIN or sys_idNOT IN