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.

Not applicable

Macro to remove and add new fields to a group

Hi,

I could use a macro to remove all fields from a group and add new fields to same group.

The amount of fields already in group is variable. So hard coded "group.RemoveField 1", "group.RemoveField 2" etc.

will not do the job.

In the example my "Test Group" has 3 fields.

if i use "group.RemoveField i" --> 1st and 3rd field are removed while 2nd remains.

if i use "group.RemoveField 0" --> only 1st field is removed

Any ideas how to modify my code?

Macro code and QVW you will find below.

Regards,

Michi

********************

sub EmptyGroup
      set group = ActiveDocument.GetGroup("Test Group")
      set gp = group.GetProperties
      set vars = gp.FieldDefs
     

      for i = 0 to vars.Count -1
           group.RemoveField i
      next

      call AddGroup
end sub

sub AddGroup
      if ActiveDocument.Variables("vFY_CY").GetContent.String = "FY" then
            group.AddField "FY1"
            group.AddField "FY2"
            group.AddField "FY3"
      else
            group.AddField "CY1"
            group.AddField "CY2"
            group.AddField "CY3"
      end if
end sub

1 Solution

Accepted Solutions
s_uhlig
Not applicable

Re: Macro to remove and add new fields to a group

Hi Michi,

for i = vars.Count -1 to 0 step -1

        group.RemoveField i

next

seems to work.

Regards

Sven

PS.: to immediately reflect the changes - call

group.Cycle 1

group.Cycle -1

after: call AddGroup

3 Replies
Not applicable

Macro to remove and add new fields to a group

Hi,

so nobody can help me?

Or is it too trivial?


Regards

s_uhlig
Not applicable

Re: Macro to remove and add new fields to a group

Hi Michi,

for i = vars.Count -1 to 0 step -1

        group.RemoveField i

next

seems to work.

Regards

Sven

PS.: to immediately reflect the changes - call

group.Cycle 1

group.Cycle -1

after: call AddGroup

Not applicable

Re: Macro to remove and add new fields to a group

Hi Sven,

thanks for your help.

It works like i hoped.

Regards

Michael