MBS FileMaker Advent calendar - Door 10 - Reading The Wish List
Day 10 - Reading The Wish List |
Welcome to Door 10. A few days have passed since we sent out our wish list forms and the first wish lists are slowly rolling in. It's time for us to incorporate readout into our solution. For this reason, we first create a container in which we can place the file to read it out and create a new script. Since we also need DynaPDF here, we must first initialize it. Then we load the file from the container into a newly created working environment as we have already seen in the previous doors.
If [ MBS("DynaPDF.IsInitialized")=0 ] Perform Script [ Specified: From list ; “InitDynaPDF” ; Parameter: ] End If # Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ] Set Variable [ $r ; Value: MBS("DynaPDF.OpenPDFFromContainer"; $pdf; Giftee::WishlistIn) ] Set Variable [ $r ; Value: MBS("DynaPDF.ImportPDFFile"; $pdf) ]
Now it's time to read the fields. First, we read the ID field to compare it with our primary key in the database so that we can make sure that the document we have received also belongs to the giftee and has not been imported into the wrong data record. We use the DynaPDF.GetField function to query a field. We first pass the reference and the name of the field to the function as parameters. Then what information we want from the field. In this case, we are only interested in the value, but text color or field flags could also be queried, for example. If this function returns an error or the ID does not correspond to the primary key, we return an error message to the user and exit the script.
Set Variable [ $ID ; Value: MBS("DynaPDF.GetField"; $pdf; "ID" ; "Value") ] If [ MBS("IsError") or $ID ≠ Giftee::PrimaryKey ] Show Custom Dialog [ "Wrong File"; "This file does not correspond to the original template" ] Set Variable [ $r ; Value: MBS("DynaPDF.ReleaseAll") ] Exit Script [ Text Result: "Wrong File" ]
But if the ID corresponds to the primary key, then we query the values of the individual fields and write them to variables first. We then assemble the variables into a list.
Else Set Variable [ $one ; Value: MBS("DynaPDF.GetField"; $pdf; "one"; "Value") ] Set Variable [ $two ; Value: MBS("DynaPDF.GetField"; $pdf; "two"; "Value") ] Set Variable [ $three ; Value: MBS("DynaPDF.GetField"; $pdf; "three"; "Value") ] Set Variable [ $four ; Value: MBS("DynaPDF.GetField"; $pdf; "four"; "Value") ] Set Variable [ $five ; Value: MBS("DynaPDF.GetField"; $pdf; "five"; "Value") ] Set Variable [ $six ; Value: MBS("DynaPDF.GetField"; $pdf; "six"; "Value") ] Set Variable [ $seven ; Value: MBS("DynaPDF.GetField"; $pdf; "seven"; "Value") ] Set Variable [ $eight ; Value: MBS("DynaPDF.GetField"; $pdf; "eight"; "Value") ] Set Variable [ $nine ; Value: MBS("DynaPDF.GetField"; $pdf; "nine"; "Value") ] Set Variable [ $ten ; Value: MBS("DynaPDF.GetField"; $pdf; "ten"; "Value") ] Set Field [ Giftee::Wishes ; $one & "¶" & $two& "¶" & $three& "¶" & $four& "¶" & $five& "¶" & $six& "¶" & $seven& "¶" & $eight& "¶" & $nine& "¶" & $ten ] Set Variable [ $r ; Value: MBS("DynaPDF.ReleaseAll") ] End If
Now, of course, we also want to display our data. On the one hand, we could display a simple custom dialog, but we also have the option of displaying a list on which we can even select things, e.g. what the recipient really gets from our Christmas Elf under the tree. The ListDialog is a dialog that can be called centrally in our solution. This means that we could, for example, make all the settings in one script and then display them in another script. However, this also means that the dialog may still contain data from a previous use in the solution. For this reason, we first call ListDialog.Reset to reset all settings so that we can set them according to our wishes without having legacy data. We can use ListDialog.SetWindowTitle to set the title of the window and ListDialog.SetPrompt to set the text in the dialog. We can also display checkboxes in front of our list elements. This allows us to make a more precise selection straight away. We show the checkboxes by specifying the value 1 in ListDialog.SetShowCheckboxes. We actually have a list with the values we want to have in the list. We can pass this list to the ListDialog.AddItemsToList function. This adds our entries to the list. If we want to add a single value to the list, we can also use the function ListDialog.AddItemToList. Now everything is set up the way we want it and we can display the list dialog with ListDialog.ShowDialog.
Set Variable [ $r ; Value: MBS("ListDialog.Reset") ] Set Variable [ $r ; Value: MBS("ListDialog.SetWindowTitle"; "Wish List") ] Set Variable [ $r ; Value: MBS("ListDialog.SetPrompt"; "Wishes of " & Giftee::first_name & " " & Giftee::last_name) ] Set Variable [ $r ; Value: MBS("ListDialog.SetShowCheckboxes"; 1 ) ] Set Variable [ $r ; Value: MBS("ListDialog.AddItemsToList"; Giftee::Wishes ) ] Set Variable [ $r ; Value: MBS("ListDialog.ShowDialog") ]
Now we can view and select the entries within the dialog. After the dialog has been closed, we can query the list of items that have been touched. For this we use the function ListDialog.GetCheckedTitles. We then save this list in a field.
Set Variable [ $List ; Value: MBS( "ListDialog.GetCheckedTitles" ) ] Set Field [ Giftee::Presents ; $List ]
We have now read in our wish list. We'll meet again tomorrow and continue to prepare for the delivery of the presents.
9 👈 | 10 of 24 | 👉 11 |