Jump to content

Creating new records based on checkbox selections


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

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!

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
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 ).

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
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.

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
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.  :-)

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
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:

Link to post
Share on other sites

This topic is 2025 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.