Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

erich_shiino
Not applicable

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.

Tags (3)
1 Solution

Accepted Solutions
disqr_rm
Not applicable

Macro to disable triggers

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.

19 Replies
disqr_rm
Not applicable

Macro to disable triggers

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.

kaushik_solanki
Not applicable

Macro to disable triggers

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

erich_shiino
Not applicable

Re: Macro to disable triggers

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

erich_shiino
Not applicable

Re: Macro to disable triggers

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

Re: Macro to disable triggers

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

Re: Macro to disable triggers

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

erich_shiino
Not applicable

Re: Macro to disable triggers

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

Macro to disable triggers

Thank you Erich.


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

Not applicable

Macro to disable triggers

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)