19 Replies Latest reply: Aug 16, 2011 5:55 AM by Sergey Petkov RSS

    Macro to disable triggers

    Erich Shiino

      Is it possible to disable triggers using macro?

      I´d like to disable triggers (like onSelect, onLock) when making selections with macro. After this I'd like to enable them back.

        • Macro to disable triggers
          Rakesh Mehta

          Try playing with Macro

           

          set docprop=ActiveDocument.GetProperties

          set actions=docprop.OnOpenActionItems

          for i=0 to actions.Count-1

          msgbox "Action types: " & actions.item(i).Type

          next

           

          Not sure about disable/enable action items, but you can always add or remove them using macro.

          Hope this helps.

            • Re: Macro to disable triggers
              Erich Shiino

              Hi, Rakesh

              This piece of code is great! I will play with it a little bit until I'm able to add and remove actions!

              Thanks a lot!

               

              Erich

               

               

              UPDATE: The following code (as an example) can add the back and the clearall actions on the field TEAM

                  set fld=ActiveDocument.GetField("TEAM")

                  set fp = fld.GetProperties

                  set actions=fp.OnSelectActionItems

                  ACTIONs.ADD

                  actions.item(0).type = 6

                  ACTIONs.ADD

                  actions.item(1).type = 4

               

                  fld.setproperties fp

            • Macro to disable triggers
              Kaushik Solanki

              Hi,

               

                  Even i couldnt found any way to enable and disable the actions.

               

                  Can you describe what actually you want to do. So that we can try some other way to achieve that

               

              Regards,

              Kaushik Solanki

                • Re: Macro to disable triggers
                  Erich Shiino

                  Hi, Kaushik

                  Thanks for looking for a way to do it.

                  I used Rakesh code to understand the QV objects a little better to be able to remove and add actions to the document and field. I'd say it's already a work-around since would be easier to do something like: Activedocument.disableActions and .enableActions

                   

                  Regards,

                   

                  Erich

                    • Re: Macro to disable triggers
                      Carlos Ramos

                      Hi Erich,

                       

                      Did you eventually find the way to remove actions or, maybe, to disable triggers?

                       

                      I specially would like to know how to remove actions. "Add" would add an action but "Remove", "Delete"... won't work!

                       

                      Thanks

                        • Re: Macro to disable triggers
                          Carlos Ramos

                          Have tried to find it (how to remove actions through a macro) in the API guide with no success:

                          - OnSelectActionItems.Add to add a new action
                          - OnSelectActionItems.Item(i).Type = nn to set the action i type
                          - OnSelectActionItems.Item(i).????? to delete action i


                          Does somone know what to put in ????? (delete, remove, ...)

                            • Re: Macro to disable triggers
                              Erich Shiino

                              Hi, Carlos.

                              The folllowings sub can add and remove actions respectively:

                               

                              sub addActions
                                  set fld=ActiveDocument.GetField("TEAM")
                              
                                  set fp = fld.GetProperties
                              
                                  set actions=fp.OnSelectActionItems
                              
                              
                              
                                  ACTIONs.ADD
                              
                                  actions.item(0).type = 6
                              
                                  ACTIONs.ADD
                              
                                  actions.item(1).type = 4
                              
                              
                              
                                  fld.setproperties fp
                              
                              End sub
                              
                              sub removeActions
                                  set fld=ActiveDocument.GetField("TEAM")
                              
                                  set fp = fld.GetProperties
                              
                                  set actions=fp.OnSelectActionItems
                              
                              for i=actions.Count-1 to 0 step -1
                              
                                  actions.removeat(i)
                               next
                              
                              
                              
                              
                                  fld.setproperties fp
                              
                              End sub
                              
                      • Macro to disable triggers
                        Carlos Ramos

                        Have tried this macro and works fine in local QV:


                        Sub UserSetting()

                        User=Lcase(ActiveDocument.GetLayout.AuthenticatedUser)
                        set fld=ActiveDocument.GetField("OSUSER")
                        set fldprop=fld.GetProperties

                        set actionsfld=fldprop.OnSelectActionItems
                        for i=actionsfld.Count-1 to 0 step -1
                        actionsfld.RemoveAt(i)
                        next

                        set actionsfld=fldprop.OnUnlockActionItems
                        for i=actionsfld.Count-1 to 0 step -1
                        actionsfld.RemoveAt(i)
                        next

                        fld.SetProperties fldprop


                        ActiveDocument.Fields("OSUSER").Unlock
                        ActiveDocument.ClearAll     
                        ActiveDocument.Fields("OSUSER").Select User (this seems not to be working in the server)
                        ActiveDocument.Fields("OSUSER").Lock


                        set actionsfld=fldprop.OnSelectActionItems
                        actionsfld.Add
                        actionsfld.Item(0).Type = 6
                        actionsfld.Add
                        actionsfld.Item(1).Type = 4

                        set actionsfld=fldprop.OnUnlockActionItems
                        actionsfld.Add
                        actionsfld.Item(0).Type = 6
                        actionsfld.Add
                        actionsfld.Item(1).Type = 28

                        fld.SetProperties fldprop

                        End Sub

                         

                        So I retrieve the OS user, eliminate the "protective" OnSelect/OnUnlock actions, unlock, set the field OSUSER to the curren user, lock again and restore the "protective" OnSelect/OnUnlock actions.

                         

                        Works perfect in local machine but not in the server (see comment in the macro code)

                        • Re: Macro to disable triggers
                          Carlos Ramos

                          Erich,

                           

                          Try the attached document: first in your desktop and then in the server.

                            • Macro to disable triggers
                              Erich Shiino

                              Sorry, I'm only able to try it on desktop.

                              And it works...

                              What if you unlock it twice?

                              After Unlock, try to check if it's locked with

                              temp=ActiveDocument.Fields("CITY").GetLocked

                              if temp then msgbox("Locked!")

                               

                              You can also use this:

                              temp=ActiveDocument.Fields("CITY").CanUnlock

                              if temp then msgbox("Can be unlocked")

                               

                              I saw this method on the API guide, but I'm not sure about the results.

                               

                              This tests are very interesting, please tell us your results.

                              We can think in some workaround if it doesn't work

                               

                              Regards,

                               

                              Erich

                                • Re: Macro to disable triggers
                                  Carlos Ramos

                                  Afirmative:

                                   

                                  I have added both messages after the lock instructions and when I run it in the server I get the messages "Locked" "Can't be unlocked"

                                   

                                  Very strange!

                                    • Re: Macro to disable triggers
                                      Carlos Ramos

                                      At the moment this issue has been reported as a possible bug.

                                        • Macro to disable triggers

                                          Hello!

                                          I have decided to use this macro to hide confidential info from some users... long story. The macro works great in QV developer! Many thanks for which.

                                          Unfortunately, the macro that is supposed to add actions when entering the tab and remove them after leaving the tab works in QV Desktop only. When I try it on server, it is not executed properly (cannot add actions, but the rest of it is executed properly (I tried with message boxes)).

                                          Is it confirmed to be a bug, or still under investigation? Any patch available so far?

                                          It is very important for me to disable "unlock and clear" only on a single tab, so that the user sees only data which is selected by a trigger/macro and to be unable to clear this selection. On all other tabs the user should be able to manipulate the same field.

                                            • Macro to disable triggers

                                              Here is the part of the documentation the QlikView Support used to prove that this is not a bug, but rather a work as designed functionality:

                                              "29.2 Macro functionality limitations

                                              Functionality that will normally work well in macros in the QlikView Server environment

                                              with any type of client is:

                                              • Logical operations such as clearing or selecting in fields

                                              • Operations related to variables

                                              The following types of functionality are not to be used in the QlikView Server environment

                                              , as they may cause unexpected results:

                                              • Layout operations acting on the properties of sheets and sheet objects via

                                              SetProperties

                                              • Operations changing document or user settings

                                              • All operations related to the script, including Reload

                                              • Data reduction operations, e.g. ReduceData

                                              • Operations such as Save and Open document "

                                               

                                              Hopefully this will save you time and efforts!

                                              Best regards,

                                              Sergey