6 Replies Latest reply on Oct 27, 2009 5:40 PM by RickWhitelaw

    Triggered Script question

    RickWhitelaw

      Title

      Triggered Script question

      Post

      Hi,

       

      I have a script triggered OnObjectEntered that changes plain text to bold and vice-versa:

       

      Triggered: Add_Remove Bold

       

      If [ PatternCount ( GetAsCSS ( Get ( ActiveFieldContents ) ); "bold") = 0 ] 

      Set Field [ TextStyleAdd ( Get ( ActiveFieldContents ); Bold ) ]

      Else

      Set Field [ TextStyleRemove ( Get ( ActiveFieldContents );Bold ) ]

      End If

       

       It works fine except I'd like it NOT to be triggered if the field is entered via the tab key (Code 9). "If Code(Get(TriggerKeystroke))<> 9" won't work as a condition with OnObjectEnter since the script isn't necessarily triggered by a Keystroke. OnObjectEnter triggers after the trigger event in any case. I want to be able to Tab to the field and enter it by clicking which triggers the script.I suspect "enter" means "enter" and that's it.

       

      Thanks. 

        • 1. Re: Triggered Script question
          raybaudi
            

          Two copy of the same field, one over the other.

           

          The frontmost with the trigger and out of the tab order, the other w/o the trigger and inserted into the tab order. 

          • 2. Re: Triggered Script question
            RickWhitelaw
              

            Raybaudi,

             

            Thanks! I'd forgotten about that technique and it's useful. Setting the text color in the background field to white (or whatever your background color is) helps text definition. Here's another script that does text formatting on individual repetitions of a repeating field:

             

            Set Variable [ $REP[Get ( CalculationRepetitionNumber )]; Value:Get ( ActiveRepetitionNumber ) ]

            Set Variable [ $FN[Get ( CalculationRepetitionNumber )]; Value:Get ( ActiveFieldTableName ) & "::" & Get ( ActiveFieldName ) ]

            If [ PatternCount (GetAsCSS (GetRepetition ( Schedule::Service; $REP)) ; "bold") = 0 ]

            Set Field [ TextStyleAdd (Evaluate(GetRepetition ( $FN;$REP )); Bold ) ]

             Else

            Set Field [ TextStyleRemove ( Evaluate(GetRepetition ( $FN;$REP ));Bold ) ]

             End If 

             

            I'd like this to work with any repeating field, but so far it's problematic.  I'd like the third line to be "If [ PatternCount (GetAsCSS (GetRepetition ( $FN; $REP)) ; "bold") = 0 ]" . This would allow the script to be triggered from any repeating field. However, although "$FN" evaluates properly (as does "$REP") and the syntax seems correct, the expression "GetAsCSS (GetRepetition ( $FN; $REP))" references only the first repetition of the field. When "GetAsCSS (GetRepetition ( Schedule::Service; $REP))" is used it evaluates the proper repetition. Looking at the script again I see that the second line should work as "Set Variable [ $FN[$REP]; Value:Get ( ActiveFieldTableName ) & "::" & Get ( ActiveFieldName ) ] and it doesn't.

               Does anyone have any ideas?

             

            RW 

            • 3. Re: Triggered Script question
              RickWhitelaw
                

              Slight change in line 2:

               

              Set Variable [ $REP[Get ( CalculationRepetitionNumber )]; Value:Get ( ActiveRepetitionNumber ) ]

              Set Variable [ $FN; Value:Get ( ActiveFieldTableName ) & "::" & Get ( ActiveFieldName ) ]

              If [ PatternCount (GetAsCSS (GetRepetition ( Schedule::Service; $REP)) ; "bold") = 0 ]

              Set Field [ TextStyleAdd (Evaluate(GetRepetition ( $FN;$REP )); Bold ) ] 

              Else

              Set Field [ TextStyleRemove ( Evaluate(GetRepetition ( $FN;$REP ));Bold ) ] 

              End If 

               

              The change? The repetition number seems irrelevant when all the variable ($FN) should capture  is the full articulation of the Field Name.

               

              Same problem 'tho (in bold-line 3). Oddly the variable $FN seems to evaluate correctly after line 3 (and before).

               

              Still open to (and hoping for ) ideas.

               

              RW 

              • 4. Re: Triggered Script question
                raybaudi
                  

                Why doing things the more difficult way ?

                 

                What is wrong with the first ( more generical ) script of your first post ?

                 

                (  Get ( ActiveFieldContents ) works even for a rep of a repeatition field ! )

                • 5. Re: Triggered Script question
                  RickWhitelaw
                    

                  Thank you,

                   

                   "(  Get ( ActiveFieldContents ) works even for a rep of a repeatition field ! )"

                   As often happens, I already had the solution for repeating fields and didn't know it! I had no idea this function worked on repetitions (as plainly spelled out in the help file).

                   

                  RW 

                  • 6. Re: Triggered Script question
                    RickWhitelaw
                      

                     Raybaudi wrote:

                     

                    "Two copy of the same field, one over the other.

                     

                    The frontmost with the trigger and out of the tab order, the other w/o the trigger and inserted into the tab order." 

                     

                    One disadvantage of this technique: once the user tabs through the background fields in the tab order then clicks (on the foreground field) he's out of the tab order. I decided in this case to stay with one foreground field and forego tabbing.

                     

                    RW