Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
erichshiino
Partner - Master
Partner - Master

Macro to disable triggers

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.

1 Solution

Accepted Solutions
disqr_rm
Partner - Specialist III
Partner - Specialist III

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.

View solution in original post

19 Replies
disqr_rm
Partner - Specialist III
Partner - Specialist III

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.

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

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

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
erichshiino
Partner - Master
Partner - Master
Author

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

erichshiino
Partner - Master
Partner - Master
Author

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

Not applicable

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

Not applicable

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

erichshiino
Partner - Master
Partner - Master
Author

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

Not applicable

Thank you Erich.


So RemoveAt(i) whas the magic word I've been trying to figure out this weekend  !!!

Not applicable

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)