Hi guys.
I'm new to complex queries with records and I've got a question about how to execute a query based on records when there is no key based relationship between two tables.
Imagine a situation where there are two tables
1. Executed jobs table
2. Hourly rates of employees
In result I need to list executed jobs with their cost. But the join between these tables is based on employee name and timestamp of job fitting into rate of employee at job execution time. Using SQL I could perform a join on multiple fields, something like
SELECT jobs.id, jobs.summary, jobs.employee, jobs.timestamp, (jobs.hours * rates.HourlyRate) as jobCostFROM jobsLEFT JOIN rates ON (jobs.employee = rates.employee AND jobs.timestamp BETWEEN rates.from and rates.to)
How to do that in the queryRecordType world?
I could do a query, and then a loop and for each job record execute a calculation with retrieving rate information. But would result in multiple SQL statements, and I'm guessing there are better ways for it, right?
And just for the sake of it, it's not that I have a small table of 4 jobs and 5 rates for 2 employees This is just an example representation of an obviously larger set of data.
Help will be much appreciated
Discussion posts and replies are publicly visible
Hello michszym,
You can create do that using a!queryRecordType(). Create two records for each of your source.
Let's say you are using it in a dropdown field.
From my understanding you want to display the Employee Name from Executed jobs table and on selection you would like to show data from Hourly rates of employees.
Create a query for your Executed jobs record type and make sure you get only the data. Create another record type query for your Hourly rates of employee record and make sure you have a filter for the employee field.
you can add filters and give the operators such as between.
You can now call your Executed Jobs record query in a local and try indexing the name of the employee as your dropdown Choice values and Choice labels.
consider another local variable for the selected employee name.
Call your Hourly rates of employee in a local variable and in that rule you need to pass the variable where you are saving the dropdown selection value. You can add multiple filters to your query and have dropdowns for passing all the values.
a!localvariables( local!employeeTable: rule!yourEmployeeQuery(), local!selectedEmployee, local!hourlyRates:rule!hourlyRates(employeeName: local!selectedEmployee), { a!dropDownField( label:"Select Employee", choiceValues:index(local!employeeTable,"recordType!field",null), choiceLabels:index(local!employeeTable,"recordType!field",null), value:local!selectedEmployee, saveinto:local!selectedEmployee, placeHolder:"Select" ), a!sectionLayout( contents:{ display your data by indexing the field from local!hourlyRates } ) } )
Make sure you have a null check for the filter/parameter.
I'm not sure if this is what your question was about. Please ignore if not.
Hope this will help.
Hi Konduru.Thanks for the reply, but that for me is not a valid solution. First of all I'm trying to display values and not get inputs. Both ways (for read/display and input) it does work for a small amount of record, and there it is valid. Cause let's say for 5 jobs shown, you are executing 1 query to retrieve these jobs, and then 5 other queries to retrieve dropdown content for each of the job entries. But imagine you have 500 jobs to display on a graph, or to build a calculation? Or a thousand of them. That would mean 501 queries or 1001. And that, even if it does the job, I would say would be not optimal - both in terms of operations needed and in terms of time needed to execute all of them.
So thanks again, but I'm still open for suggestions and answers how to tackle that.
Hi michszym, I Think it will query only once and it will give us the desired output. Since you will be selecting the value from the dropdown your query will run only once and will give you the data. You can use this data to display the values.
Maybe you are right, and this could work. But we are not using it in a grid with dropdown. I want to display stuff in a chart, with also summary and avarage values displayed. So this dropdown option is out of consideration I'm afraid.