I have a problem where I have a list of fields from a table (not static, can be modified by user), and I need to generate a report using these user selected fields. The report can show all the rows, no need for aggregation or filtering.
I thought I could create a report layout then using a filemaker script to populate it but can't seem to find the right commands, can someone let me know how I could achieve this?
I'm using filemaker pro 18 advanced
Thanks in advance!
EDIT: Since you want a dynamic report, then I recommend you look up a technique called "Virtual List" for rendering the data.
Here's an example script that iterates over a found set of records and builds the virtual list data in a variable (it doesn't show how to render it though):
# Field names and delimiter
Set Variable [ $delim ; Value: Char(9) // tab character ]
# Set these dynamically with a script parameter
Set Variable [ $fields ; Value: List ( "Contacts::nameFirst" ; "Contacts::nameCompany" ; "Contacts::nameLast" ) ]
Set Variable [ $fieldCount ; Value: ValueCount ( $fields ) ]
Go to Layout [ “Contacts” (Contacts) ; Animation: None ]
Show All Records
Go to Record/Request/Page [ First ]
# Loop over all the records and append a row in the $data variable for each
Set Variable [ $data ; Value: "" ]
Loop
# Get the delimited field values
Set Variable [ $i ; Value: 0 ]
Set Variable [ $row ; Value: "" ]
Loop
Exit Loop If [ Let ( $i = $i + 1 ; $i > $fieldCount ) ]
Set Variable [ $value ; Value: GetField ( GetValue ( $fields ; $i ) ) ]
Insert Calculated Result [ Target: $row ; If ( $i > 1 ; $delim ) & $value ]
End Loop
enter code here
# Append the new row of data to the list variable
Insert Calculated Result [ Target: $data ; If ( Get ( RecordNumber ) > 1 ; ¶ ) & $row ]
Go to Record/Request/Page [ Next ; Exit after last: On ]
End Loop
# Save to a global variable to show in a virtual list layout
Set Variable [ $$DATA ; Value: $data ]
Exit Script [ Text Result: ]
please note this code is just one of many possible formats the virtual list can take. A lot of people, myself included, prefer to use JSON objects or arrays for each row of the list since it automatically handle field values with carriage returns. This is sort of the old-fashioned way. Kevin Frank at FileMaker Hacks has some good recent articles about virtual list techniques if you're interested.
PS, another great technique for rendering table data dynamically is to collect the data in a JSON array and render it in a webviewer with https://datatables.net/
I did something like this for the oncology department of UM om 1980 or so using 4th Dimension and a new plug in that used one line of code to create a web browser with all the functions that a doctor might want. The data was placed inside a variable as it was sent/returned and 4D could use a variable in the report to display the data.
FileMaker does not have this ability built in as 4D did so you will have to do it yourself.JSON is the most likely tool that I am familiar with. YouTube has many videos on JSON.
You have two classes of variables for your report: Column headers and column data to display. Fortunately Filemaker is quite good and very easy to design. Just make a typical report and replace the text/header or field names with a JSON variable or any. $ColumnName = JSON variable.
Create a JSON calculated field in the database. In that calculated field set the JSON variable and this can be used for all of the columns.
This is the essence of the idea with the final result to be determined by you. What you are asking for is not easy and would require serious work by a skilled JSON scripter.
Related
I have one table with 3 columns.
id
start
end
I am applying one function on table , function with 3 arguments.
Ex:Function1(id,start,end)
This function is working when I pass static value to it.but I want to run this function on full table.
How to do this?
This my use case Actually
datatable(id:string, start:string,end:string)
[
'Z213',datetime(2021-08-06T02:12:37.1597030Z),datetime(2021-08-06T17:37:21.8962890Z),
'Z213',datetime(2021-08-06T00:00:25.7896310Z),datetime(2021-08-06T01:59:50.1172850Z),
'Z213',datetime(2021-08-06T02:04:37.1243340Z),datetime(2021-08-06T02:12:37.1352020Z),
'Z213',datetime(2021-08-06T17:45:19.7289570Z),datetime(2021-08-06T23:56:44.8047730Z),
'Z213',datetime(2021-08-06T17:43:23.7238020Z),datetime(2021-08-06T17:43:28.7256000Z),
'Z213',datetime(2021-08-06T02:04:17.1238770Z),datetime(2021-08-06T02:04:24.1256730Z),
'Z213',datetime(2021-08-06T02:02:15.1199760Z),datetime(2021-08-06T02:02:15.1204780Z),
]
|invoke function1('Z213',datetime(2021-08-06T02:12:37.1597030Z),datetime(2021-08-06T17:37:21.8962890Z))
So when I pass this 1st row then it will work fine .
but I want do this like
|invoke Function (id,start,end)
Take a look at the tabular functions here is an example:
let append_to_column_a=(T:(a:string), what:string) {
T | extend a=strcat(a, " ", what)
};
datatable (a:string) ["sad", "really", "sad"]
| invoke append_to_column_a(":-)")
I have a list in a DynamoDB table and would like to move items to different positions in the same list, is there a way to do this in a single update?
At the moment, I'm looking at having to read the list, modify it, then write it back again, but would prefer doing it all in a single update, is there a way to do this?
Edit to add example
So here's some noddy data that shows what I'd like to do:
If the data started like this:
Item: { COLUMN: [ "Element_0", "Element_1", "Element_2", "Element_3" ] }
Then I'd give it from and to indices and it would move the element. So for example if I gave it a from index of 0 and to index of 2 the data should end up like this:
Item: { COLUMN: [ "Element_1", "Element_2", "Element_0", "Element_3" ] }
You can do this with an Update Expression, but it's a little tricky, since you don't have the data.
Basically, you have to create a dynamic update statement that sets every value you want to move. Something like this works:
aws dynamodb update-item --table-name test --key '{"pk":{"S":"1"}}' --update-expression "SET #list[1] = #list[2], #list[2] = #list[1]" --region us-west-2 --profile jw-test --expression-attribute-names '{"#list": "list"}'
I created a table with a key of pk, with a value of 1. The list before the update was like this:
[
'one',
'two',
'three',
'four'
]
After the update it looks like this:
[
'one',
'three',
'two',
'four'
]
Default answer if this isn't possible in a single update.
Read out the list, modify it, then write it back. It's not elegant, but it works and isn't that ugly either.
It's not atomic though so any answer that can do it in a single update will get the check mark.
I have written a fairly complicated code for my ABM (634 agents having interactions, each having different variables some of which are lists with multiple values that are updated each tick). As I need to save the updated values for all agents, I have defined a global variable using table:make. This table has 634 keys (each key for one agent), and each key has a list of those values (from that agents-own list variable) for the correspondent agent. But when I use the name of this table to be reported as one of my outputs in Behavior Space, the result in csv file is a table with no keys and it has only a number in it: {{table: 1296}}. So, I was wondering how I could change this variable to be able to have all values.
If you're happy to do some post-processing with R or something after the fact, then table:to-list might be all you need. For example, with a simple setup example like:
extensions [ table ]
globals [ example-table ]
turtles-own [ turtle-list ]
to setup
ca
crt 3 [
set turtle-list ( list random 10 one-of [ "A" "B" "C" ] random 100 )
]
set example-table table:make
foreach sort turtles [
t ->
table:put example-table ( word "turtle_" [who] of t ) [turtle-list] of t
]
reset-ticks
end
And a to-report to clean each table item such that the first item is the key and all other items are the items in the list:
to-report easier-read-table [ table_ ]
let out []
foreach table:to-list table_ [ i ->
set out lput ( reduce sentence i ) out
]
report out
end
You can set up your BehaviorSpace experiment such that one of your reporters is that reporter, something like:
To get a .csv file like:
Where the reporter column outputs a list of lists that you can process how you like.
However, I probably wouldn't use the basic BehaviorSpace output for this, but instead have a call in the experiment to call a manual table output procedure. For example, using the csv extension to make this output-table procedure:
to output-table [ filename_ table_ ]
let out [["key" "col1" "col2" "col3"]]
foreach table:to-list table_ [ i ->
set out lput ( reduce sentence i ) out
]
csv:to-file filename_ out
end
This outputs a much more analysis-ready table if you're less comfortable cleaning the output of a list-of-lists that as far as I know is what you would get from the BehaviorSpace output. So, you can either call it at the end of your experiment, like:
To get a table like:
Which is a little nicer to deal with. You can obviously modify this to report more often if needed, for example:
which would output a table at each tick of the experiment (you can also do this in your code to make it a little easier).
I'm using firebase database to store a complex data structure, it looks like this:
../thousand_island/
genomes:[
0:{
"somthing": "some content"
},
... 49 more
],
version: 1223
The genomes array always have 50 elements. Every time I call set to replace all the data in /my_record_name then 50 new records will be inserted into the genomes array instead of replacing.
Code sample:
// set the ref into the instance
this.ref= firebase.database.ref('/genomes/thousand_island');
...
// record = { genomes:[...], version: *** }
if(version> record.version){
this.ref.set(record,function(){
console.log('updated thousand_island ', version, '->', record.version);
})
}
So how to make it replace it instead of appending to the array? I was thinking of deleting the data then insert again but it sounds tedious and it costs 2 requests.
I'm using List() to retrieve a numeric field which I subsequently display on a report view via a merge variable inside a text field. The data being displayed is a list of employees who worked on a particular job on a particular day, and the number of hours they worked under various classifications (normal, overtime, non-billable, non-billable overtime, et al). The hours are all calculated fields pulled from another table, but they need to be stored numerically.
Each column has its own text field:
| <<$$Name>> | <<$$normalHours>> | <<$$otHours>> | ...
Giving output such as:
Jim Jones 8 2
Ralph Ryder 4.25 0
Foo McBar 10 2.5
The field height needs to be dynamic because there could be anywhere from 1 to 10 or so employees displayed.
The issue is that I would like to always display the hours field with two decimal places:
Jim Jones 8.00 2.00
Ralph Ryder 4.25 0.00
Foo McBar 10.00 2.50
This is normally trivial via Inspector -> Data for a single-value field, and perhaps it still is trivial -- but I'm just not seeing it.
I've tried using SetPrecision(hours ; 2) when populating the field, and also (though I didn't think it would actually work) when creating my list variable:
$$normalHours = SetPrecision( List( laborTable::normalHours ) ; 2 )
In both cases I still see plain integer output for whole numbers and no trailing zeroes in any case.
Please let me know if I can provide any further information that might help.
A few things you can try:
Auto-enter calculation replacing existing value
You could change your normalHours field to be an auto-enter calculation, uncheck 'do not replace existing value', and set the calculation to the following:
Let ( [
whole = Int ( Self ) ;
remainder = Abs ( Self ) - Abs ( whole )
] ;
Case ( remainder = 0 ;
whole & ".00" ;
Self )
)
This will append a ".00" to any whole numbers in your field. This should then come through your List() function later.
New calculation field
Alternately, if you don't want to automatically modify the existing number, you could make a new calculation field with a very similar calculation:
Let ( [
whole = Int ( normalHours ) ;
remainder = Abs ( normalHours ) - Abs ( whole )
] ;
Case ( remainder = 0 ;
whole & ".00" ;
normalHours )
)
And then you would use that calculation field in the List function, instead of your normalHours field.
For more complicated field formatting, you could also use a custom function like this: http://www.briandunning.com/cf/945
Can you replace this with a portal, perhaps?
If not, then try to set formatting on the merge text field itself. It can have formatting too; only one variant for each data type, but in your case it should be enough.