Your script has several issues that would exist even if it worked correctly.
- Go to Portal Row lacks the means to specify which portal it is to act on. On layouts where there is more than one portal, it will interact whith whichever portal currently has the focus. An extra step: Go to Object, should be used just before go to portal row to make sure the focus is set on the correct portal record.
- Copy will replace any data your user has copied to the clipboard prior to performing your script. This tends to confuse and irritate user when they then attempt to paste the copied data and find that they have pasted the data copied by your script. There are other ways to do this that don't use copy and thus you don't have to create such a problem for your users.
- Copy, Paste and Insert all require that the fields they reference are physically present on the current layout. Should you ever edit your layout at some future time to remove the field, the script silently fails to copy, paste or insert the data. The only way you know that a failure has occurred is that the script fails to produce the expected result. This issue and the issue in item 2 can be avoided by using set variable and set field.
Now to fix the actual problem you are having here. Where do you want to see this result displayed? In the portal? Outide of the portal? Since your script only references the first portal row to access data, why do you need a portal at all for this?
Please describe the relationship you have for your portal.
It's very possible that you can get what you need here without using any script at all depending on your answers to those questions.
Set Field [ The Field You Want The Answer In ; Calculation = Second Field - Field From Portal )
...should work if the portal is not sorted and not filtered.
But may be more flexible for later if you let the user click on the portal row they mean, and then run this script as they click on the row:
Set Variable [ $FirstNumber ; That Field In The Portal Row ]
Set Field [ The Field You Want The Answer In ; Calculation = Second Field - $FirstNumber ]
This also stops messing with the user's clipboard. It will apply to any portal row the user clicks on.
Answer to PhilModJunk:
I want the result displayed OUTSIDE the Portal.
I need a Portal because the Portal displays several fields in several rows from a relationship with other table.
The relationship displays several fields but in waht concerns my issue I'm only interested in one numerical field and not in the others.
A possible option: to obtain the result I want with a calculation. My problem: I was not able to find a function dealing with Portal Fields.
Thank you for your answer
Answer to Sorbsbuster,
I will try your directions. I guess they are the best way to solve my issue.
Thank you very much
But your script only references the first record in the portal. That's what Go to portal Row [first] does. Thus, it's not clear to me why you need any portal at all here.
The first row in a portal is going to be the first related record unless you specify a sort order for the portal and/or a portal filter. If the portal is not sorted or filtered and you want your calculation to refer to only the data in the first row of your portal, then this calculation can be defined for a calculation field in your layout's table:
2 * ( FieldExternalToPortal - PortalTable::FieldInsidePortal )
But I have to wonder from your posts if you are confusing what is meant by a field and what is meant by a portal row here...
I need to do the calculation with the numeric field of the Portal because the Portal ONLY gives the records where certain conditions
are present. If not was the case, I could solve the problem with a simple calculation, between the field of database (and not this same field
in the portal) and the field outside portal.
More simply explained:
My database has the Numeric Field "Vib" with variable contents.
The portal displays the Field "Vib" when the relationship conditions are carried out.
Outside the portal there is another numeric field " Valor"
I want calculate the result Vib-Valor.
First, I tried to solve the issue with a calculation field where the result will be displayed.
But I didn't find a Function to access Portal Fields.
So, I tried to create a Script. You are right: "Go to Portal Row" (First) only allows, if possible, the First Portal Row.
And I need to access all the rows where the Field "Vib" reports a value. (second, third, and so on)
Hope I could explain my issue clearly.
Thank you very very much
" need to do the calculation with the numeric field of the Portal because the Portal ONLY gives the records where certain conditions are present."
That's what the relationship that the portal is based on does. You don't have to display the portal to access the (first) matching record.
"But I didn't find a Function to access Portal Fields." - use the same relationship to access the fields for the calculation as you use for the portal.
"And I need to access all the rows where the Field "Vib" reports a value. (second, third, and so on)" - but now I'm a bit lost, sorry.
If you want to calculate the result for the first row first, then later for the second row etc, you can use the idea of clicking on the portal row you are interested in to set the field with the result you want.