10-27-2010 01:43 PM
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.
10-28-2010 07:34 AM
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();
10-28-2010 07:34 AM
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();
10-29-2010 11:14 AM
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(); } } }