Jump to content

Random Child Records


falkaholic

This topic is 6532 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi guys,

I want have a portal with 5 random child records in it. Nothing to fancy, I've come up with a couple ideas on how to do it, but niether really give me that warm fuzzy feeling:

1. Sort the portal on a value list. The value list will a field with randon data in it. Then have the portal only show 5 records. Not sure if that will work nice or not.

2. Have a field in the child records have a random field and sort the portal on it. Again showing 5 records only. The problem is the random field needs to be generated on every record all the time.

Anyone got a better way(s)?

Link to comment
Share on other sites

A calculation like:

GetNthRecord ( Child::ChildID ; Ceiling ( Random * Count ( Child::ChildID ) ) )

could pick a random ChildID for a key field in the Parent. The problems are that (a) being an unstored calculation, it would revaluate on every scren refresh, and (:) you need 5 UNIQUE ID's. I think I would populate the key field by a script:

Set Field [ Parent::ScriptedKey; "" ]

Loop

Exit Loop If [ ValueCount ( Parent::ScriptedKey ) ≥ 5 ]

Set Field [ Parent::ScriptedKey; Let ( item = GetNthRecord ( Child::ChildID ; Ceiling ( Random * Count ( Child::ChildID ) ) ) ; Parent::ScriptedKey & Case ( IsEmpty ( FilterValues ( item ; Parent::ScriptedKey ) ) ; item & ¶ ) ) ]

End Loop

Link to comment
Share on other sites

This topic is 6532 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.