Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

Highlighted
Not applicable

Clear selection in multiple fields

Hi everyone,

I'm Trying to set a triger that Clears selections in multiple fields in many places in my QV model.

Is there a way I can do this without defining a "clear field" action to each field? Maybe some kind of a concatenated string that can clear multiple fields with only one "clear field" action.

I know macro can solve this but i rather not to use it...

Thanks,

John

9 Replies
trdandamudi
Honored Contributor II

Re: Clear selection in multiple fields

Is the clear button is not an option for what you are trying to do ?

Not applicable

Re: Clear selection in multiple fields

As far as I know, clear button can clear one field or all fields - not multiple

Not applicable

Re: Clear selection in multiple fields

folow

santiago_respane
Valued Contributor

Re: Clear selection in multiple fields

Hi,

with a combination of clear all and lock field you can achieve that.

Example: you have a field called myField that shouldn't be cleared.

Do as follows:

  • Create button
    • Actions
      • Lock field for myField
      • Clear all
      • Unlock field for myField


Hope this helps.

Kind regards,

Not applicable

Re: Clear selection in multiple fields

Thanks Santiago,

This way I have to add an action to each field I want to lock, isn't it so? This is what I want to avoid from

santiago_respane
Valued Contributor

Re: Clear selection in multiple fields

Hi,

i think that you will always have to mention every field that you want to lock, but maybe this suits you better.

  • Create button
    • Actions
      • Call LockFields Macro
      • Clear all
      • Call UnLockFields Macro

Then in your module you create two macros as follows:

Sub LockFields

ActiveDocument.Fields("Field1").Lock

ActiveDocument.Fields("Field2").Lock

End Sub

Sub UnLockFields

ActiveDocument.Fields("Field1").UnLock

ActiveDocument.Fields("Field2").UnLock

End Sub

Please let me know if this helps.

Kind regards,

santiago_respane
Valued Contributor

Re: Clear selection in multiple fields

Or maybe this one is better for you.

Create a variable with the field names to lock\unlock:

v.Fields = 'FIELD1|FIELD2|FIELD3';

Module code:

'Gets the value from specific variable passed through varName parameter

FUNCTION getVariableValue(varName)

  set v = ActiveDocument.Variables(varName)

  getVariableValue = v.GetContent.String

END FUNCTION

'Locks all fields in the v.Fields Variable

Sub Lock

fields =split( getVariableValue("v.Fields"),"|")

for each field in fields

    ActiveDocument.Fields(field).Lock

next

End Sub

'UnLocks all fields in the v.Fields Variable

Sub UnLock

fields =split( getVariableValue("v.Fields"),"|")

for each field in fields

    ActiveDocument.Fields(field).Unlock

next

End Sub

This way you'll only have to change your variable.

Please let me know if this helps you solving your issue.

Kind regards,

Re: Clear selection in multiple fields

Yes, If you don't need to use the macro than you need to add a action trigger for each field and specify  all the values that need to be cleared ..

yakir_manor
New Contributor III

Re: Clear selection in multiple fields

this can be annoying, i wrote a code that will only clear the fields that are selected, you can check this qvw, this also allows you to just list those fields in an island instead of repeating code.