Community
Showing results for 
Search instead for 
Do you mean 
Reply

Adding Current Client to a specific Group

Accepted Solution Solved
Copper Super Contributor
Posts: 478
Country: Australia
Accepted Solution

Adding Current Client to a specific Group

Hi all

 

I have struggled with this one for a few days now and just cant get over the last hump and make the code work

 

I grab the list of groups the Current Contact is a member of, and i have the name of the desired group, it cycles through to check if already a member

 

Now if not i want to add the CurrentContact as a member, i have the command code for it but just cant work out how to add the actual Group to the code line

 

 

 

 

 

 

                GroupList gl2 = ActApplication.Instance.ActFramework.Groups.GetGroupsByStaticContact(c, null);
                
                string glname1 = "Asset Test Review";
                string gpmember1 = "No";

                foreach (Group g2 in gl2)
                {
                    string glname2 = gName.GetValue(g2).ToString();
                    if (glname1 == glname2) gpmember1 = "Yes";
                    MessageBox.Show("Contact " + gpmember1 +" a member of the " + glname1 + " group", "", MessageBoxButtons.OK);
                }
                
                if (gpmember1 == "No")
                {
                    gl2.AddNew(glname1);
                    ActApplication.Instance.ActFramework.Groups.UpdateContactStaticMembership(c, null, gl2);
                }

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6

Accepted Solutions
Solution
Accepted by topic author JasonD
‎01-28-2016 12:12 PM
Copper Super Contributor
Posts: 478
Country: Australia

Re: Adding Current Client to a specific Group

Ah Huh SUCCESS!!!!!!

 

I got something to work, realised i was not Update() the group ... hehehe

 

This is the code so far

 

                GroupList gl1 = ActApplication.Instance.ActFramework.Groups.GetGroups(null);
                
                MutableEntityFieldDescriptor gName = ActApplication.Instance.ActFramework.Groups.GetMutableEntityFieldDescriptor("TBL_GROUP.NAME", true);

                GroupList gl2 = ActApplication.Instance.ActFramework.Groups.GetGroupsByStaticContact(c, null);
                
                string glname1 = "Asset Test Review";
                string gpmember1 = "No";

                List<Guid> guids = new List<Guid>();
                Guid cid = c.ID;
                guids.Add(cid);

                ContactList clist = ActApplication.Instance.ActFramework.Contacts.GetContactAsContactList(c);
                //GroupList glist = ActApplication.Instance.ActFramework.Groups.GetGroupAsGroupList(glname1);

                foreach (Group g2 in gl2)
                {
                    string glname2 = gName.GetValue(g2).ToString();
                    if (glname1 == glname2) gpmember1 = "Yes";
                }
                
                if (gpmember1 == "No")
                {

                    foreach (Group g1 in gl1)
                    {
                        string glname3 = gName.GetValue(g1).ToString();
                        Guid gid = g1.ID;
                        if (glname1 == glname3)
                        {
                            g1.AppendStaticContacts(clist);
                            g1.Update();
                        }
                        //if (glname1 == glname3) ActApplication.Instance.ActFramework.Groups.UpdateContactStaticMembership(c, null, GroupList);

                    }
                                        
                }

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6

View solution in original post


All Replies
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Adding Current Client to a specific Group

[ Edited ]

If I remember correctly the way that you do it is create an arraylist of objects and add your groups to the arraylist and then convert the arraylist to a grouplist and add the grouplist back (directcast(myArraylistOfGroups, act.framework.groups.grouplist) or (GroupList)myArraylistOfGroups in C#).  If that doesn't work for you let me know and I'll find a snippet of code where I've actually done it and post it back.

 

I think there also might be an example of doing it in this forum.  Possibly with either a contactlist or a companylist but the procedure is still the same.

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Copper Super Contributor
Posts: 478
Country: Australia

Re: Adding Current Client to a specific Group

Thanks for the reply Stan, firstly did not understand word of what you said Smiley Happy its still odd to me that you have a list why not just add one to it

 

while hunting around for your converting idea i did find another cast to add the contact but unfortunetly it to needs a list

 

I can not locate the sample in the forum


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Copper Super Contributor
Posts: 478
Country: Australia

Re: Adding Current Client to a specific Group

hmm may have stumbled across something

 

 

But this line does not appear to co-op

 

                ContactList clist = ActFramework.Contacts.GetContactsByID(null, guids);

 

 

Full code

 

 

                GroupList gl1 = ActApplication.Instance.ActFramework.Groups.GetGroups(null);
                
                MutableEntityFieldDescriptor gName = ActApplication.Instance.ActFramework.Groups.GetMutableEntityFieldDescriptor("TBL_GROUP.NAME", true);

                GroupList gl2 = ActApplication.Instance.ActFramework.Groups.GetGroupsByStaticContact(c, null);
                
                string glname1 = "Asset Test Review";
                string gpmember1 = "No";
                List<Guid> guids = new List<Guid>();
                Guid cid = c.ID;
                guids.Add(cid);

                ContactList clist = ActFramework.Contacts.GetContactsByID(null, guids);

                foreach (Group g2 in gl2)
                {
                    string glname2 = gName.GetValue(g2).ToString();
                    if (glname1 == glname2) gpmember1 = "Yes";
                    MessageBox.Show("Contact " + gpmember1 +" a member of the " + glname1 + " group", "", MessageBoxButtons.OK);
                }
                
                if (gpmember1 == "No")
                {

                    foreach (Group g1 in gl1)
                    {
                        string glname3 = gName.GetValue(g1).ToString();
                        Guid gid = g1.ID;
                        if (glname1 == glname3) g1.AppendStaticContacts(clist);
                        //if (glname1 == glname3) ActApplication.Instance.ActFramework.Groups.UpdateContactStaticMembership(c, null, GroupList);
                    }
                                        
                }

 


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Adding Current Client to a specific Group

[ Edited ]

I always wondered why the various lists didn't have an add method myself.  I know a lot more about programming than I used to so I may be able to get that to work now though.  I'll see if I can come up with a little code that will do it.

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Adding Current Client to a specific Group

 

I had a long conversation with a developers regarding an ADD feature many years ago at a conference such as:

Me.HostApplication.ApplicationState.CurrentContactList.ADD(myContact)

 

It seems like s small issue but actually is a large lift since you also need to convert the Me.HostApplication.ApplicationState.CurrentContactQuery

 

Dim CurrentQueryType As UILookupManager.SimpleContactQuery.ContactQueryType = DirectCast(DirectCast(Me.HostApplication.ApplicationState.CurrentContactQuery, Act.Framework.Contacts.IContactSource), Act.UI.UILookupManager.SimpleContactQuery).QueryType

 

At that time I wanted to add contacts to a list in a specific order like when older version of ACT did a lookup of contacts based on an activity list. Older version would give you the contact list in order of the activities dateTime.

 

New ACT gives you the same contact list but the order is the current sort order from the sort order criteria.

Me.HostApplication.ApplicationState.CurrentContactList.SortCriteria

 

Hope this helps

-- Jim Durkin

 

 

Copper Super Contributor
Posts: 478
Country: Australia

Re: Adding Current Client to a specific Group

Thanks for that but it will take me a while to digest

 

I did also find this

 

                ContactList clist = ActApplication.Instance.ActFramework.Contacts.GetContactAsContactList(c);

Which VS has no problems with and the code all runs... but nothing happens the client does not join the group


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Solution
Accepted by topic author JasonD
‎01-28-2016 12:12 PM
Copper Super Contributor
Posts: 478
Country: Australia

Re: Adding Current Client to a specific Group

Ah Huh SUCCESS!!!!!!

 

I got something to work, realised i was not Update() the group ... hehehe

 

This is the code so far

 

                GroupList gl1 = ActApplication.Instance.ActFramework.Groups.GetGroups(null);
                
                MutableEntityFieldDescriptor gName = ActApplication.Instance.ActFramework.Groups.GetMutableEntityFieldDescriptor("TBL_GROUP.NAME", true);

                GroupList gl2 = ActApplication.Instance.ActFramework.Groups.GetGroupsByStaticContact(c, null);
                
                string glname1 = "Asset Test Review";
                string gpmember1 = "No";

                List<Guid> guids = new List<Guid>();
                Guid cid = c.ID;
                guids.Add(cid);

                ContactList clist = ActApplication.Instance.ActFramework.Contacts.GetContactAsContactList(c);
                //GroupList glist = ActApplication.Instance.ActFramework.Groups.GetGroupAsGroupList(glname1);

                foreach (Group g2 in gl2)
                {
                    string glname2 = gName.GetValue(g2).ToString();
                    if (glname1 == glname2) gpmember1 = "Yes";
                }
                
                if (gpmember1 == "No")
                {

                    foreach (Group g1 in gl1)
                    {
                        string glname3 = gName.GetValue(g1).ToString();
                        Guid gid = g1.ID;
                        if (glname1 == glname3)
                        {
                            g1.AppendStaticContacts(clist);
                            g1.Update();
                        }
                        //if (glname1 == glname3) ActApplication.Instance.ActFramework.Groups.UpdateContactStaticMembership(c, null, GroupList);

                    }
                                        
                }

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6