Forums
Extending Daylite
Building Reports and Print Layouts
resolving KeyPath token(?) in F-Script token|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Journeyman |
What is the general syntax for getting the value of a keypath element into an f-script (token)?
Assume I have a table drawing data from a form that consists of field A and field B. Field A = parent.reportData.object.A Field B = parent.reportData.object.B So, how do you refer to these values? Is there something along the lines of x := value(Field A) since the f-script would already know the context it's in -- Or do you do something along the lines of x := objectContext some.path.to.field A ? Or neither? So assume Field A and Field B are numbers, and I wanted the sum, just how would the f-script look? here's hoping... |
||
|
|
Marketcircle Team |
The syntax would be:
x := reportElement valueForKeyPath:'parent.reportData.object'. reportElement is the element that contains the token. Not knowing what you are planning to do, I'm assuming you want to make this behave like a spreadsheet cell. There is one problem - if that cell's value is derived (calculated), then it may not be resolved by the time your script runs. The safer route is get the values directly from the object(s) and then do your calculation as opposed to depending on the result of a cell. BTW: reportData is a dictionary so you can use it to store variable using something like this: data := reportElement valueForKeyPath:'parent.reportData'. data setObject:'my variable' forKey:'theThing'. The following keys are reserved: object, objects, name, index, groupBy. If you use this, you have to be careful in which order you use this (think of the tree). I think we have to add some mechanism at the top level so you can setup commonly used, calculated, variables. |
|||
|
|
Journeyman |
Thank you so much, AJ. I'm really close to this I think, but still not getting it.
I should just be able to show the value for the field in this case by the following, right? x := reportElement valueForKeyPath:'parent.reportData.object.A'. x But nuthin'. I also tried x := reportElement valueForKeyPath:'parent.reportData.object'. x.A which is a long-shot I'm sure, but thought maybe I was confused regarding the path (which I probably am). Regarding storing variables- that is very cool. I just have to get the really easy stuff out of the way first! Thank you~ |
|||
|
|
Marketcircle Team |
There are 3 variables here:
1) 'parent.reportData' could be 'parent.parent.reportData'. The positioning is relative, so you have to make sure you know where to look. 2) it could be 'object' or 'objects'. 'objects' is an array of items as opposed to a single item (such as a contact). 3) the 'A' after 'object' is not valid. If 'object' was a contact, then something like 'firstname' would be valid. Hopefully this helps you navigate the tree to get your data. |
|||
|
|
Journeyman |
Okay, I'm starting to feel really stupid, but I just don't get this- What element are we talking about? The Data Row? The Table? The field itself? How do you actually refer to this element within a dynamic text? Let's say I've got a report, 1 strip, 1 table, table is a query from Project. I want to show Extra Field1. I can add this as a normal key token with parent.reportData.object.extra1 Now I want to show this exact same value using a F-Script token: x := extra1 getValueForKeyPath:'parent.reportData.object'. -Nope. undefined identifier "extra1" If this was outside a dynamic text, wouldn't it probably be like x := Project getValueForKeyPath:'parent.reportData.object.extra1'. ? Since extra1 is a key of Project? This doesn't work either within the dynamic text tho. So how the heck do you determine what reportElement is? Thanks! |
|||
|
|
Marketcircle Team |
Ah - good question - which element?
The best way to explain this is too look at a diagram we have in the Report Engine doc. Page 18 in the June 11 Draft. The whole system is a tree with branches and leafs. Each branch and leaf is an element. In this case, the report element is the dynamic text element. |
|||
|
|
Marketcircle Team |
Eric,
I have an embarassing admission - I make a mistake earlier - the variable for the report element is not 'reportElement' - it is 'element'. I think I owe you a few beers. Sorry!! |
|||
|
|
Marketcircle Team |
So if you want to get the extra1 field in the f-script you do this: x := element valueForKeyPath:'parent.reportData.object.extra1'. This is assuming you are in a dynamic text element inside a row inside a table. To get the whole project object, it would be this: proj := element valueForKeyPath:'parent.reportData.object'. To get the array (list) of projects, it would be: projects := element valueForKeyPath:'parent.parent.reportData.objects'. It is parent.parent because the projects are on the table and not on the row. Damn - I feel bad about that reportElement mistake. Sorry again. |
|||
|
|
Journeyman |
Wow, that makes a world of difference...
Thank you ~ I thought I was losing it there. Perhaps when things settle down we could get a "Basic functions with F-Script" page or two added in the Report docs or something. It looks like element always returns a string? No big deal, I figured out coercion, just curious. Never thought that half my time with DayLite would be spent in X-Code's documentation! We're talking industrial strength contact management now! |
|||
|
| Previous Topic | Next Topic | powered by eve community |
| Please Wait. Your request is being processed... |
|
Forums
Extending Daylite
Building Reports and Print Layouts
resolving KeyPath token(?) in F-Script token
