1 2 Previous Next 17 Replies Latest reply on Nov 27, 2013 12:41 PM by philmodjunk

# Help with a Calculation for a Portal Record Set

### Title

Help with a Calculation for a Portal Record Set

### Post

Hoping Some one can help! I have an idea how to achieve what I need but have found others who help on the forum build much smaller less cumbersome calculations than me! Hope Im explaining what a need clear enough.

I have a portal set to show 10 rows. if the portal has for example 21 records

I have a field gRecordSet which when "1" is entered the portal shows record 1-10     "2" 11-20    "3" 21

I want to set the gRecordSet field not to go over the needed record sets of 10  ie if 21  records then gRecordSet only goes up to 3

If Child::PortalSum <= 10 and >= 1

Set field    Parent::gRecordSet    "1"  (no other value can be added)

If  Child::PortalSum > 10

Child::PortalSum / 10

average to nearest 1+                      (ie if portal sum = 21 / 10 = 2.1   result =3)

Result

field    Parent::gRecordSet         ( ie  field must only have numbers 1 2 or 3 to be able to be entered)

• ###### 1. Re: Help with a Calculation for a Portal Record Set

Set Field [Parent::gRecordSet ; If ( (gRecordset + 1 ) * 10 - 9 > Count ( child::foreignkey ) ; gRecordset ; gRecordset + 1 ) ]

you can use any field from child in place of foreignkey as long as it is never empty.

• ###### 2. Re: Help with a Calculation for a Portal Record Set

To calculate an integer you're on the right track. Divide the record number by 10 and use Ceiling (recordNumber/10) which rounds up to the next integer and truncates all the decimals.

You might use a Value List based on that number field for your portal filter and the whole thing is fully automated no matter how the list grows and shrinks.

• ###### 3. Re: Help with a Calculation for a Portal Record Set

Hi phil

the calculation works on the way up ie when I have the portal populated with 9 records I get Result 1  19 result 2  29 result 3

but when I reduce the records back down to 19 and 9 gRecordSet stays on result 3!

I was thinking that the fact I will be adding a + and - button to view the portals (like the demo you posted from yesterday) would it be better to just set the gRecordSet from buttons with the relevant calculation

• ###### 4. Re: Help with a Calculation for a Portal Record Set

Apoligies my inexperience interpreted the calculation wrong. I was putting the calculation in gRecordSet

I created another field called gPortalSet and put the calculation in it!

I works up until 20 ie   1-10 =1    11-20 =2    21-30 =2 it might be something with the Child::field Im using will playaround with it

• ###### 5. Re: Help with a Calculation for a Portal Record Set

Yes, I was thinking in terms of the + and - buttons that I used in the demo file that I shared in the other thread. You can also use Case and limit values so that values less than zero are not allowed either.

Here's code that works as an update to the script in that file:

Set Field [Parent::gRecordSet ;

Case ( (gRecordset + Get ( ScriptParameter ) ) * 10 - 9 > Count ( child::foreignkey ) ; gRecordset ;
(gRecordset + Get ( ScriptParameter ) ) * 10 - 9 < 1 ; gRecordSet ;
gRecordset + 1
) // Case

] // this bracket is part of your script step, don't type it into the calculation

The + button passes a parameter of 1 and the - button passes -1.

• ###### 6. Re: Help with a Calculation for a Portal Record Set

Hi Phil Im having no luck

Am I right in thinking the above calculation goes into gRecordSet Calculation field   - the last bracket

and as a script in both buttons  passing the 2 relevant parameters

• ###### 7. Re: Help with a Calculation for a Portal Record Set

Open my demo file, open the only script in it for editing. What I just posted would be used in place of the set field step found in that script, but with the field names defined in it instead of yours.

And yes, this is a script performed when you click either button so long as you use the parameters that I have specified.

• ###### 8. Re: Help with a Calculation for a Portal Record Set

Ok understand!

The minus button not behaving as it should. it keeps incrementing UP + by 1

The plus button behaving properly

• ###### 9. Re: Help with a Calculation for a Portal Record Set

Then I would guess that it is not passing -1 as the parameter.

• ###### 10. Re: Help with a Calculation for a Portal Record Set

Tried all my knowledge will allow

I deleted the  -1 Parameter on the minus script to see how the script would behave. it still adds 1!

Will do a bit of searching on why parameter not passing.

Many Thanks

• ###### 11. Re: Help with a Calculation for a Portal Record Set

Are you clicking the button while in FileMaker Pro or tapping the button on an iOS device?

• ###### 12. Re: Help with a Calculation for a Portal Record Set

Only using on Filemaker pro 12

• ###### 13. Re: Help with a Calculation for a Portal Record Set

If you had advanced, I'd suggest using the script debugger and data viewer while stepping though the script.

Since you don't, I'd suggest adding a show custom dialog step temporarily. Set it to show the value of Get ( ScriptParameter ) and the value of key fields and the expressions in your script steps and see if anything pops up with the wrong value.

• ###### 14. Re: Help with a Calculation for a Portal Record Set

As you know I'm only getting to grips with FM so I could only get the script parameters and fields to popup!

parameters are showing in the message box as 1 for + button    and -1 as -minus button!

Not sure if what I've noticed has any impact in working out the fault but I set the records to 26 and gRecordSet to 1

I clicked PLUS Button until it stopped at 3 then clicked Minus Button which incremented up twice before it stopped at 5

1 2 Previous Next