Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to create a group dynamically from editscript

Hi,

I have a table in the editscript that is generated from the qvdfile. that table like(Test) Has 3 columns with 10 rows of data.I have loaded that table in to the qlikview. From the frontend i have created a group with those table columns.Right now this is good .But in future  the data may increases for those table(like new columns may be added).But my group doesn't have the updated values.So,what my requirement is how to update the group automatically from the editscript.

Is it possible to update my group from the editscript....

Please share your valuable information with your replies to me  and this is an urgent requirement.

Thanks in advance,,,,,

26 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

     It seems that you have not seen the example i sent you.

     Anyways,

  

     Do one thing. Copy yhe macros in module.

     At sheet create a button with action -> external -> Macro -> give the macro name -> Remove_Group  

      And try.

      Cause it works my side.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

Hi kaushik,

Actually i am not having full version Qlikview so i cannot open your attached file.

But i had added your macro in the button for both Add and Remove script.

When i am working with it, then it is only adding but not removing. 

The Code which you given is correct but when removing it is not removing the fields.

For Adding Process:

1.)We need to select the field from listbox and then we need to click on the button for Adding the field into Group.

In the same way what is the process for Removing

For Removing Process:

How  ???

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

    Follow the below steps.

    Copy the script in module. Click on check button. It should show you below names.

    Add_Group

    Add_grp(..)

    Remove_Group

    Remove_Grp(..)

    Click ok button.

    On your sheet, create a button give name as remove-> go to action tab. ->Click on add-> Click on External -> Run Macro-> give the macro name as Remove_Group

    and click ok.

   Try this and let me know.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

Thanks Kaushik.

I got the solution from your post.

Thnks

Not applicable
Author

Hi Kaushik,

Thanks for your support but i am really sorry to disturb you again.

Actually when i am removing the more than two or three fields at a time then the macro is showing an error. First two fields is removing and after that it is opening an macro code and highliting one line in the code.

I am marking the error place with "Red color". Please go through and can you forward an reply how to solve this.

sub add_Group
''groups=ActiveDocument.GetGroups
''groups(0).AddField "OrderID"
counter = 0
set LB = ActiveDocument.GetSheetObject("LB14")
boxvalues=LB.GetPossibleValues
for i = lbound(boxvalues) to ubound(boxvalues) 
  count = count + 1  
next
if count = LB.GetRowCount  then
msgbox "Please select one dimension"
Exit sub
else
    'field = boxvalues(0)
    for i = lbound(boxvalues) to ubound(boxvalues) 
  field = boxvalues(i)
  call Add_grp(field)
next
end if

end sub

sub Remove_Group
''groups=ActiveDocument.GetGroups
''groups(0).AddField "OrderID"
counter = 0
set LB = ActiveDocument.GetSheetObject("LB14")
boxvalues=LB.GetPossibleValues
for i = lbound(boxvalues) to ubound(boxvalues) 
  count = count + 1  
next
if count = LB.GetRowCount  then
msgbox "Please select one dimension"
Exit sub
else
    'field = boxvalues(0)
    for i = lbound(boxvalues) to ubound(boxvalues) 
  field = boxvalues(i)
  call Remove_grp(field)
next
end if

end sub

sub Add_grp(field)
set group = ActiveDocument.GetGroup("bc")
set gp = group.GetProperties
set vars = gp.FieldDefs
for i = 0 to vars.Count-1
    set fld = vars(i)
    'msgbox("field " & i+1 & " is " & fld.Name)
    if field = fld.name then
     counter = 1
    end if
next

if counter = 0 then
group.AddField field
msgbox field &" is Added to Group"
counter = 1
end if
end sub
''set group = ActiveDocument.GetGroup("New Group")
''set gp = group.GetProperties
''msgbox(gp.Present)

sub Remove_grp(field)
set group1 = ActiveDocument.GetGroup("bc")
set gp = group1.GetProperties
set vars = gp.FieldDefs
for i = 0 to vars.Count-1
    set fld = vars(i)
    'msgbox("field " & i+1 & " is " & fld.Name)
    if field = fld.name then
     group1.RemoveField i
     msgbox  field &" is Removed From Group"
     exit sub
    else
     counter1 = 0
    end if    
next

if counter1 =0 then
msgbox field & "is not in group"
counter1 =1
end if
end sub

Thnks

Not applicable
Author

HI Kaushik,

I am attaching the file you have attached to me, in that i am adding few more fields in INLINE.

So now the listbox contains few more fields like User1,User2,User3.

Now Select the first 4 fields from listbox and then click on Add buttton; upto here its working fine.

Now if i am removing the same fields which i added into Group then the macro is Highliting One line with black color.

*****************+++++++++++++++++++++++**********************

And one more if am selecting all the fields at a time in listbox and then i am clicking the button of either Add or Remove then it is showing a message "Please Select One Dimension"

Pls can you provide a solution on this . I'm waiting for your reply..

Thnks in advance...

Not applicable
Author


Hi Kauchik.

This is brilliant.

Now I just have to figure out some clever use for it in my apps.

Thank you very much.

regards

Torbjörn Lättman