Community
Showing results for 
Search instead for 
Do you mean 
Reply

Trouble finding a way to set the Company Dynamic Member settings via the SDK.

Accepted Solution Solved
New Member
Posts: 3
Country: USA
Accepted Solution

Trouble finding a way to set the Company Dynamic Member settings via the SDK.

Hi Yall,

 

I'm a newbie to ACT and would like roll through the companies and set the dynamic membership.  I can see the table on the backend that controls this "TBL_COMPANYQUERY" but can figure out how to insert values there via the SDK (working with 2010 standard).  If I could get some sample code that set just inserts one I can figure out the rest I think. 

Thanks in advance for your help.


Accepted Solutions
Solution
Accepted by topic author colotaz
‎09-25-2015 03:20 AM
Employee
Posts: 1,163
Country: USA

Re: Trouble finding a way to set the Company Dynamic Member settings via the SDK.

Hello colotaz,

 

This example will set the dynamic criteria for the current company to any contacts who has a company name equal to the current company. Hope this gets you going in the right direction:

 

Company c = ActApp.ApplicationState.CurrentCompany;
CompanyFieldDescriptor cName = ActApp.ActFramework.Companies.GetCompanyFieldDescriptor("TBL_ CONTACT.COMPANYNAME"true);
CriteriaColumn col = ActApp.ActFramework.Lookups.GetCriteriaColumn(cName);
Criteria crit = new Criteria(LogicalOperator.End, 0, 0, col, OperatorEnum.EqualTo, c.Name);
c.SetCriteria(new Criteria[1] { crit });

c.Update();
Matthew Wood
Act! SDK Support
Community Moderator

View solution in original post


All Replies
Solution
Accepted by topic author colotaz
‎09-25-2015 03:20 AM
Employee
Posts: 1,163
Country: USA

Re: Trouble finding a way to set the Company Dynamic Member settings via the SDK.

Hello colotaz,

 

This example will set the dynamic criteria for the current company to any contacts who has a company name equal to the current company. Hope this gets you going in the right direction:

 

Company c = ActApp.ApplicationState.CurrentCompany;
CompanyFieldDescriptor cName = ActApp.ActFramework.Companies.GetCompanyFieldDescriptor("TBL_ CONTACT.COMPANYNAME"true);
CriteriaColumn col = ActApp.ActFramework.Lookups.GetCriteriaColumn(cName);
Criteria crit = new Criteria(LogicalOperator.End, 0, 0, col, OperatorEnum.EqualTo, c.Name);
c.SetCriteria(new Criteria[1] { crit });

c.Update();
Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 3
Country: USA

Re: Trouble finding a way to set the Company Dynamic Member settings via the SDK.

Thanks that got me in the ballpark! 

 

For the people that follow here is the code I built to look at an existing relationship between two fields in Contacts and Companies then sent set the dynamic company Members.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Act.Framework;
using Act.Framework.Lookups;





namespace AssociateCompanies2
{
    class Program
    {
        static void Main(string[] args)
        {
            //Declare some vars
            string linkValue; // Value that will go in the filter
            Act.Framework.Contacts.ContactFieldDescriptor cName; //Field (Contact) that will be filtered on
            int errCnt = 0; 
            //Open textfile for logging
            TextWriter tw = new StreamWriter(@"c:\temp\ACTDynamicCompanyUpdate.txt");
            tw.WriteLine("=======Load Start ===========  "+ DateTime.Now.ToString());

            Console.WriteLine("Starting Update");


            //Start to Log on
            ActFramework framework = new ActFramework(); //Init framework for ACT

            //Set path to the Pad file (db file)


                //Test DB
                    //string actDBPath = @"SomeTestPath"; 
                //Prod DB
                    string actDBPath = @"SomePath"; //Set path to the Pad file (db file)


            framework.LogOn(actDBPath, "User", "PW");// Logon
           

            //Get list of all companies
            Act.Framework.Companies.CompanyList companyList = framework.Companies.GetCompanies(null);


            foreach (Act.Framework.Companies.Company c in companyList) //Loop through companyies
            {
            

           
                //Get Current company HCSystem value and Hospital Value
                string curHCS = c.Fields["HCSystemFK", Act.Framework.MutableEntities.FieldNameType.Alias].ToString();
                string curH = c.Fields["HospitalFK", Act.Framework.MutableEntities.FieldNameType.Alias].ToString();     


                //Clear Vars
                linkValue = null;
                cName = null;

                //Hospital or System
                
                if (curH == "-1" &&  int.Parse(curHCS) > 0)
                {
                    //this is a system
                    cName = framework.Contacts.GetContactFieldDescriptor("HCSystemFK", Act.Framework.MutableEntities.FieldNameType.Alias);
                    linkValue = curHCS;
                }
                else if (int.Parse(curH) > 999 && int.Parse(curHCS) > 0)
                {
                    //this is a hospital
                    cName = framework.Contacts.GetContactFieldDescriptor("HospitalFK", Act.Framework.MutableEntities.FieldNameType.Alias);
                    linkValue = curH;
                }
                else //This company has failed to update.
                {
                    Console.WriteLine("===========================> Error <===============================================");
                    Console.WriteLine(c.Name.ToString() + " was not updated!!!!!!!!!!! |" + curH.ToString() + " | "+ curHCS.ToString());
                    errCnt = errCnt + 1;

                    continue; //Go to the next hospital
                };


                //set the Column that the company will be filtered on
                CriteriaColumn col = framework.Lookups.GetCriteriaColumn(cName);

                //Build the criteria 
                Criteria crit = new Criteria(LogicalOperator.End, 0, 0, col, OperatorEnum.EqualTo, linkValue);
                c.ClearCriteria(); //Clear existing
                c.SetCriteria(new Criteria[1] { crit });//Set new
                
                c.Update();

                //Confirm update
                //Console.WriteLine( c.Name.ToString() + " updated with " + linkValue );
                tw.WriteLine(c.Name.ToString() + " updated with " + linkValue + " " + DateTime.Now.ToShortTimeString());


            }// Loop end
            tw.WriteLine("=======Load Complete with  " + errCnt.ToString() + " Errors." + DateTime.Now.ToShortTimeString());
            framework.LogOff();
            tw.Close();


        }
    }
}