1 2 Previous Next 16 Replies Latest reply on Jan 7, 2016 2:40 PM by fitch

    Switch layout based on field value

    jp98

      I need help to create a script that changes the layout (stickers/labels) based on the contents of a field in a record. If a certain field contains "DB" or "DRIB", it needs to switch to a different layout or sticker shape. this change also needs to apply when printing so that when the records print, the ones that have "DB" or "DRIB" in them automatically use the different layout.

        • 1. Re: Switch layout based on field value
          fitch

          Let's say your field is named "category." Make a script something like:

           

          If[ category = "DB" ]

             go to layout[ stickers ]

          Else If[ category = "DRIB" ]

             go to layout[ stickers ]

          Else

             go to layout[ labels ]

          End If

           

          Now you'll need to trigger that script when navigating to a record, and I would imagine when you select a category as well.

           

          In layout mode, right-click the category field, select Set Script Triggers; select On Object Modify; and choose the script and say OK.

           

          Now go to the Layout menu, choose Layout Setup, click the Script Triggers tab; select OnRecordLoad and choose the script and say OK.

           

          This only works one record at a time. If you're printing a mixed group of records, then you may need a solution that's based on hiding objects on a single layout rather than switching layouts.

          2 of 2 people found this helpful
          • 2. Re: Switch layout based on field value
            jp98

            thanks for your help.

             

            will the [ category = "DB" ] work when there are other characters within the same field. eg. DB142 or something like that

             

            we will generally be printing a mixed set of records so do you have any ideas how to create a solution that's based on hiding objects?

             

             

            do you just mean have a shape that covers the whole record and is set to cover if field contains those values?

            • 3. Re: Switch layout based on field value
              fitch

              Have a look at the Text functions. For example you might use: Left( category; 2 ) = "DB"

               

              But without knowing all the details, I can't say whether that will be sufficient.

               

              Your original post mentioned different sticker shapes. I'm familiar with sheets of labels that come in different dimensions. But I'm not sure what we're talking about when you want to mix different shapes on the same layout. Maybe you could describe what you're doing with a little more detail.

              • 4. Re: Switch layout based on field value
                jp98

                yes it is sort of like sheets of labels but all the products are in the same table and the products with DB and DRIB at the start of the product code need to have a different shaped label. this may not be possible but I was hoping there would be some solution

                • 5. Re: Switch layout based on field value
                  fitch

                  So the label sheets are not pre-cut? Are we talking rectangular shapes or what?

                  • 6. Re: Switch layout based on field value
                    jp98

                    no we print on to a4 sheets and then cut them out. the shapes are rectangular yes.

                    • 7. Re: Switch layout based on field value
                      fitch

                      Won't it be a pain to cut them if they're all different sizes? Are both the horizontal and vertical dimensions different?

                       

                      How many at a time do you print? Maybe you just need a simple script that does a Find for "DB" and "DRIB" and prints those, then find the others and goes to the other layout and prints.

                      • 8. Re: Switch layout based on field value
                        jp98

                        that does sound like a suitable option and I will just have a small print labels button to trigger the script.

                         

                        how would I format the script? like in what order should everything be?

                        • 9. Re: Switch layout based on field value
                          fitch

                          I would suggest you create a script, and create a comment in the script for each process you'll need. E.g.:

                           

                          1. Find the DB/DRIBs

                          2. Go to layout x

                          3. Print

                          etc.

                           

                          Then go back and flesh it out with actual script steps. It's easier than you think. Give it a try and come back if you get stuck.

                          • 10. Re: Switch layout based on field value
                            jp98

                            I got stuck when it came to doing the find - I got the same process as you but when it performed the find it didn't work and the printer started going hard out until I deleted the job!!!

                             

                            Items__1::CodeID is the field that it needs to search in and the first search needs to be for records that either have DB or records that have DRIB in them. the second search is the opposite.

                             

                            can you tell me how to write the find for that please.

                             


                            The go to layout and print I was obviously able to do no worries - and I will just hide the print dialog and go show all records in between the two finds

                            • 11. Re: Switch layout based on field value
                              fitch

                              While it's possible to do a Find by specifying the find requests within a single Perform Find script step, I prefer to use separate steps to explicitly build the Find. This makes it easier to maintain and troubleshoot later. So:

                               

                              Enter Find mode

                              Set Field[ Items__1::CodeID; "DB" ]

                              New Record/Request

                              Set Field[ Items__1::CodeID; "DRIB" ]

                              Perform Find

                               

                              Be sure that you don't specify the find requests within the Enter Find or Perform Find steps.

                               

                              After you print the found records, you can simply do:

                               

                              Show Omitted Only

                               

                              ... assuming there are no other criteria. I.e., we're working with all the records in the table, not just some for a particular client or something.

                               

                              If you want to up your Find game, have a look here:

                              Finding text and characters

                              • 12. Re: Switch layout based on field value
                                jp98

                                thanks so much!! works like a charm!!

                                • 13. Re: Switch layout based on field value
                                  jp98

                                  how can I reference different scripts from a custom dialog? I want to be able to reference one script if the user wants to print all records and reference another script if the user wants to print only the current record

                                  • 14. Re: Switch layout based on field value
                                    fitch

                                    Get(LastMessageChoice) returns a 1, 2, or 3 based on the dialog button clicked.

                                    1 2 Previous Next