Jump to content
Sign in to follow this  
bruceiow

open layout at a random record

Recommended Posts

Hi guys, thanks for the great forum - I have learned a great deal in the weeks since I have been using FM.

 

Can I ask a couple on data access when a layout is opened please.

 

It looks like the default position is for a layout to open and display the last entered record. Is there any control over this (i.e adding parameters like sql would). So only open recors where field x equals value z for example. 

 

Also I have a requirement to open a layout and display a record at random from any that are available in the table the layout is pointed to. The key is the random bit here! it must be different each time if possible!

 

Many many thanks

Share this post


Link to post
Share on other sites

The "Random" function will give you a number between 0 and 1 (not including 1).  So if you multiply that with the record count of the table (and round it up) it will give you a random record number.  Then use the Go To Record script step to take you there.

 

As to "So only open records where field x equals value z for example", that sounds like a find request that gets executed as part of the scripted workflow that takes the user to the layout.

Share this post


Link to post
Share on other sites

To open a layout and have a random record appear, use script trigger OnLayoutEnter with script step of:

Go To Record/Request/Page [ by calculation ; Random * Min ( Get ( FoundCount ) ; Get ( TotalRecordCount ) ) ]

... but do you want it to do this based upon total records in the table?  What if only a found set is being displayed?  You may wish to include a Show All Records and use Get ( TotalRecordCount ).  I included instead how to handle this situation by modifying the calculation above.

 

As for your first request, the best answer would depend upon the purpose and type of data.  For instance, if the record must hold a person's name in field called AccountName then it is best to use Security to restrict the User.  You could also use OnLayoutEnter to perform a find for the desired records.  Can you explain the purpose here?  


I didn't see Wim's response before posting. :-)

Share this post


Link to post
Share on other sites

Thanks guys - this is for a random quipp when completing an arduous process, so security isn't a concern here. 

 

Thanks so much, I have adopted a solution from your suggestion :)

Share this post


Link to post
Share on other sites

BTW, I should mention that my calculation will include record 1 but will not include the highest record.  If you add a 1 to the end of the calc then it will include the highest record but not record 1 (as Wim indicates).  

 

Actually, this works and includes both record 1 and the highest record:

Int ( 
Random * Min ( Get ( FoundCount ) ; Get ( TotalRecordCount ) ) + 1
)

Share this post


Link to post
Share on other sites

The "Random" function will give you a number between 0 and 1 (not including 1).  So if you multiply that with the record count of the table (and round it up)

 

Not including 1,  but including 0. That's why you cannot round up. You must round down, then shift the 0 point to the minimum of the desired range (1 in this case, since record numbering starts from 1).

 

 

 

Go To Record/Request/Page [ by calculation ; Random * Min ( Get ( FoundCount ) ; Get ( TotalRecordCount ) ) ]

 

Why is this necessary::

Min ( Get ( FoundCount ) ; Get ( TotalRecordCount ) )

Is there a scenario where Get ( FoundCount ) can be larger than Get ( TotalRecordCount )?

Share this post


Link to post
Share on other sites

Why is this necessary::

Min ( Get ( FoundCount ) ; Get ( TotalRecordCount ) )

Is there a scenario where Get ( FoundCount ) can be larger than Get ( TotalRecordCount )?

 

AAAKKKK!!  Of course ... the found count IS the total count if all records are shown ... and I knew it but forgot in this instance.  Then the calculation could be simpler and will handle all record sets:

Int ( 
Random * Get ( FoundCount ) + 1
)

If you see a better way please do tell ... learning the best approach is ALWAYS the most important thing.  Thank you again!  :-)

BTW, I didn't want to use Get ( TotalRecordCount ) because if there was a smaller found set, the Go To Record step would fail if it tried to jump to a number higher than available.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

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