Jump to content
Sign in to follow this  
etsmarines

Creating new records based on checkbox selections

Recommended Posts

If i have a checkbox field. How can i make a script that goes through the checkbox selections and creates a new record for each selection i choose.

 

Example

 

Checkbox field...

 

B

C

 

If I check A and C

 

I want to have a script that goes to a new table and creates a new record for each selection

 

New Table

 

Record A

Record C

 

Thanks again for the help!

Share this post


Link to post
Share on other sites

I assume the checkbox is a global field.  Script could look something like this pseudo script:

 

THIS IS FOR A FIND. PLEASE SEE FOLLOWING SCRIPT TO CREATE NEW RECORDS

If [ IsEmpty ( table::gCheckbox ) ]
Show Custom Dialog [ Message: "Please enter a value"; Buttons: “OK” ]
Exit Script
End If
#
Enter Find Mode [  ]
Loop
  Exit Loop If [ Let ( $count = $count + 1 ; $count > ValueCount ( table::gCheckbox ) ) ]
  New Record/Request
  Set Field [ yourDataField ; GetValue ( table::gCheckbox ; $count ) ]
End Loop
Set Error Capture [ On ]
Perform Find [  ]
If [ not Get ( FoundCount ) ]
Show Custom Dialog [ "No records found." ]
End If 

However, you can also use this checkbox set to GTRR ( Go To Related Records) if you make it the parent key to the table holding the records (even if it is this same table, known as a self-join).  You can join this global checkbox to the field, represented in this script as 'yourDataField'.

 

added End If in the script

Edited by LaRetta
  • Like 1

Share this post


Link to post
Share on other sites

LaRetta, I think the OP wants to create new records from a value list, not find any …

 

btw, you could exit the request loop by using ( Get RequestCount ).

Share this post


Link to post
Share on other sites

Ooops!  Thank you, Oliver!

If [ IsEmpty ( table::gCheckbox ) ]
Show Custom Dialog [ Message: "Please enter a value"; Buttons: “OK” ]
Exit Script
End If
#
Go To Layout [ your new table layout where records should be created ]
Loop
  Exit Loop If [ Let ( $count = $count + 1 ; $count > ValueCount ( table::gCheckbox ) ) ]
  New Record/Request
  Set Field [ yourDataField ; GetValue ( table::gCheckbox ; $count ) ]
End Loop

Share this post


Link to post
Share on other sites

btw, you could exit the request loop by using ( Get RequestCount ).

 

I hadn't seen your add-on ... yes you can.  You can even use Get ( RecordNumber ) and Get ( FoundCount ) instead as:

Enter Find Mode [ ]
Loop
Exit Loop If [ Get ( FoundCount ) > ValueCount ( global checkbox ) ]
Set Field [ dataField ; GetValue ( global checkbox ; Get ( RecordNumber ) ) ]
New Record/Request
End Loop
Perform Find [ ]
...

Many script steps in FileMaker are interchangeable in this way depending upon the mode you are in at the time. :-)

This is in response to the FIND script originally posted and not the New Record script posted after.

 

Caveat:  You must make sure you are in Find mode or you will create new records and Get ( RecordNumber ) and Get ( FoundCount ) will be based upon your actual data and not the value count of the checkbox.  Not good.

 

Normally, using a variable when you loop is standard practice.

Share this post


Link to post
Share on other sites

Hi ets,

 

If i have a checkbox field. How can i make a script that goes through the checkbox selections and creates a new record for each selection i choose.

Example

 

Checkbox field...

B

C

 

If I check A and C

I want to have a script that goes to a new table and creates a new record for each selection

 

New Table

Record A

Record C

 

I’m a little bit curious as to why you are creating new blank records based on your Record A and C?

Tell us what the purpose is of these new blank records?

 

Lee

Edited by Lee Smith
change my wording a little

Share this post


Link to post
Share on other sites

Hi Lee,

 

The new records are created based upon the checkbox field results (only containing A and C) and not based upon the value list of the checkbox.

 

... the OP wants to create new records from a value list, not find any …

 

I believe that eos meant checkbox field and not value list here.  The script provided uses the checkbox field and not the value list.  :-)

Share this post


Link to post
Share on other sites

I understood that part. I don’t understand the new records with a single entry of A or C.

Share this post


Link to post
Share on other sites

This comes up often for creating join records such as in a Survey ...

 

EXAMPLE

 

Questions -< Responses >- Answers

 

Creating responses to a Question, using a value list of potential Answers.  Provide a User Response checkbox then create the join records from the selections.  In this example, we would also include the current table's primary key.  But you are correct in that we do not know how this will be used.

  • Like 1

Share this post


Link to post
Share on other sites

 

 

Questions -< Responses >- Answers

Oh, that's clever - wouldn't have thought of that.

Share this post


Link to post
Share on other sites

I believe that eos meant checkbox field and not value list here

 

Just to be clear: I meant a value list (as in: a list of values, i.e. the current field contents – which of course could just be a single-value value list) – not the value list (the pre-defined one that the field is formatted with).

This comes up often for creating join records such as in a Survey ...

EXAMPLE

Questions -< Responses >- Answers

 

Any join table record creation - e.g. roles, line items, StudentsInClass – where you select from a list of parentsB – actors, products, students – to add them to parentA – a movie, an invoice, a class …  :smile:

Share this post


Link to post
Share on other sites

It was the use of a join table as responses to a test or survey I hadn't thought of.

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.