Community
Showing results for 
Search instead for 
Do you mean 
Reply

How to add new history Items to selected companies in VB

Accepted Solution Solved
New Member
Posts: 2
Country: United_Kingdom
Accepted Solution

How to add new history Items to selected companies in VB

I am new to ACT and am having great difficulty in finding vb code examples. I want to add History records to selected companies in ACT. The Histories.createHistory methods have far too many attributes, ie contacts, group etc that I don't need and don't know what to do with, and the company attribute is a companylist that I canot find how to fill with a single company.  Any help on this and how to fill the various atributes would be great.


Accepted Solutions
Solution
Accepted by topic author Ensa
‎09-25-2015 03:20 AM
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: How to add new history Items to selected companies in VB

[ Edited ]

 

I have found the SDK passes EntityLists to methods much more often then is passes the single entity.

ie. It expects a ContactList rather then a single Contact most of the time even if you only want to create a history on one contact. To simplify this the SDK has a method to convert a single contact into a contact list.

 

Here is an example SDK method where it is creating a history expecting a contact list:

ACTAPP.ActFramework.Histories.CreateHistory(ContactList, _

Guid.Empty, _

New Act.Framework.Histories.HistoryType(Act.Framework.Histories.SystemHistoryType.LetterSent), _

False, _

DateTime.Now, _

DateTime.Now, _

"Regarding String", _

"DetailsString")

 

But at the time you want to call CreateHistory all you know is the current contact from the UI. Replace the ContactList

variable with the GetContactAsContactLst method.

  

ACTAPP.ActFramework.Histories.CreateHistory(

ACTFramework.Contacts.GetContactAsContactList(ACTApplication.ApplicationState.CurrentContact), _

Guid.Empty, _

New Act.Framework.Histories.HistoryType(Act.Framework.Histories.SystemHistoryType.LetterSent), _

False, _

DateTime.Now, _

DateTime.Now, _

"Regarding String", _

"DetailsString")

 

This ideas on single to plural is carried out on all the top level entities

 

 

ActFramework.Groups.GetGroupAsGroupList(ACTApplication.ApplicationState.CurrentGroup)

ActFramework.Companies.GetCompanyAsCompanyList(ACTApplication.ApplicationState.CurrentCompany)

ActFramework.Groups.GetGroupAsGroupList(ACTApplication.ApplicationState.CurrentGroup)

ActFramework.Opportunities.GetOpportunityAsOpportunityList(ACTApplication.ApplicationState.CurrentOpportunity)

 

 

BTW- If you are not attaching the history to any groups then pass , Nothing,  for the groupList.

 

Hope this helps

 

-- Jim Durkin

View solution in original post


All Replies
Employee
Posts: 1,163
Country: USA

Re: How to add new history Items to selected companies in VB

Normally I'd just supply the code, but I don't program in VB so I'm not sure it'd be useful to you.

 

Unless I'm mistaken you can pass null values in lieu of providing a ContactList or GroupList. As for creating a CompanyList that contains a single company, if your able to capture the company your wanting to create the history for, you can simply create a new CompanyList and populate it with the single company. The psuedo code would look something like:

 

Company c = ActApplication.ActFramework.ApplicationState.CurrentCompany;

CompanyList cl = new CompanyList();

cl[0] = c;

 

Again, apologize for using a syntax you may be unfamiliar with.

 

If your having issue with any other parameters for this method feel free to ask again in this thread.

Matthew Wood
Act! SDK Support
Community Moderator
Solution
Accepted by topic author Ensa
‎09-25-2015 03:20 AM
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: How to add new history Items to selected companies in VB

[ Edited ]

 

I have found the SDK passes EntityLists to methods much more often then is passes the single entity.

ie. It expects a ContactList rather then a single Contact most of the time even if you only want to create a history on one contact. To simplify this the SDK has a method to convert a single contact into a contact list.

 

Here is an example SDK method where it is creating a history expecting a contact list:

ACTAPP.ActFramework.Histories.CreateHistory(ContactList, _

Guid.Empty, _

New Act.Framework.Histories.HistoryType(Act.Framework.Histories.SystemHistoryType.LetterSent), _

False, _

DateTime.Now, _

DateTime.Now, _

"Regarding String", _

"DetailsString")

 

But at the time you want to call CreateHistory all you know is the current contact from the UI. Replace the ContactList

variable with the GetContactAsContactLst method.

  

ACTAPP.ActFramework.Histories.CreateHistory(

ACTFramework.Contacts.GetContactAsContactList(ACTApplication.ApplicationState.CurrentContact), _

Guid.Empty, _

New Act.Framework.Histories.HistoryType(Act.Framework.Histories.SystemHistoryType.LetterSent), _

False, _

DateTime.Now, _

DateTime.Now, _

"Regarding String", _

"DetailsString")

 

This ideas on single to plural is carried out on all the top level entities

 

 

ActFramework.Groups.GetGroupAsGroupList(ACTApplication.ApplicationState.CurrentGroup)

ActFramework.Companies.GetCompanyAsCompanyList(ACTApplication.ApplicationState.CurrentCompany)

ActFramework.Groups.GetGroupAsGroupList(ACTApplication.ApplicationState.CurrentGroup)

ActFramework.Opportunities.GetOpportunityAsOpportunityList(ACTApplication.ApplicationState.CurrentOpportunity)

 

 

BTW- If you are not attaching the history to any groups then pass , Nothing,  for the groupList.

 

Hope this helps

 

-- Jim Durkin

New Member
Posts: 2
Country: United_Kingdom

Re: How to add new history Items to selected companies in VB

Many thanks to Mathew Wood and particularly to Jim Durkin for your rapid responce and help with this problem.

 

Jim’s example for Contacts was used for my needs in Companies with minor adjustments. The problem areas were converting company to companyList and defining the variable for HistoryType. Both of these were solved by Jim.


It was easy to get confused however with the object browser throwing up different variations of CreateHistory (ie HistoryManager.CreateHistory) and intellisense not working as expected. With so many overloads it was difficult to see the wood from the trees when an exception was shown.


However it is now working fine so I have included some of the most important lines of code below.

 

Dim myACTFW As New Act.Framework.ActFramework
  ' myACFW.Logon(----------.pad,user)

Dim myHistory As Act.Framework.Histories.History
Dim myCompany As Act.Framework.Companies.Company
 '  (myCompany is a known company supplied by an external method)
Dim hisType As Act.Framework.Histories.HistoryType =
New Act.Framework.Histories.HistoryType
(Act.Framework.Histories.SystemHistoryType.LetterSent)

Dim myCompanies As Companies.CompanyList = 
myACTFW.Companies.GetCompanyAsCompanyList(myCompany)


myHistory = myACTFW.Histories.CreateHistory
(Nothing, Nothing, myCompanies, Guid.Empty, hisType,_
False, DateTime.Now, DateTime.Now, "RegardingString",_
"DetailString", Nothing)

myHistory.Update()

 

Again Many Thanks:- Nigel Sage

 

Copper Super Contributor
Posts: 478
Country: Australia

Re: How to add new history Items to selected companies in VB

Hi All

 

I have a VB Code problem as well and was wondering if this could be a clue to helping me solve it?

 

Act-Premium/Email-Linkage-and-VB-Code-Question

 

Could i add VB code like this to my existing Outlook code that would add history items in Act? therefore working around the issue i discribed in the above forum post?

 

Thanks

 

Jason

 

 

 


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
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: How to add new history Items to selected companies in VB

I do not know the answer but it does sound like ACT may be picking up the event before your outlook VB code fires.

 

Have you tried to fire the send email from inside ACT!? You could either create your own email using Outlook as below:

 

PublicSharedFunction SendEmailviaOutLook(ByVal sEmailAddress AsString, _

ByVal ccList AsString, _

ByVal sEmailBody AsString, _

ByVal sEmailSubject AsString, _

ByVal lCreateHistory AsBoolean, _

ByVal lReturnReceipt AsBoolean, _

ByVal lIsPrivate AsBoolean, _

ByVal sAttachments AsString, _

ByVal lPreview AsBoolean, _

ByVal HTMLFormat AsBoolean) AsBoolean

       

Try

           

Dim oOutLook AsNew Outlook.Application

Dim oMailItem As Outlook.MailItem

oMailItem = DirectCast(oOutLook.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)

oMailItem.To = sEmailAddress

oMailItem.CC = ccList

 oMailItem.Subject = sEmailSubject

           

If HTMLFormat Then

                oMailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML

Else

                oMailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatPlain

EndIf

oMailItem.HTMLBody = sEmailBody

           

ForEach objLine AsObjectIn  Strings.SplitDelimitedLine(sAttachments, ",", """")

               

If IO.File.Exists(DirectCast(objLine,  MySection).Section) Then

                    oMailItem.Attachments.Add(

DirectCast(objLine,  MySection).Section)

               

EndIf

           

Next

           

If lPreview = TrueThen

                oMailItem.Display()

Else

                oMailItem.Send()

EndIf

           

ReturnTrue

       

Catch ex AsException

       LogError.Write(ex, "SendEmailviaOutLook: sEmailAddress")

EndTry

Return False

EndFunction

 

'//---------------------------------------------------

'Or send email using the ACT UIEmailManager

'//---------------------------------------------------

 

PublicSharedFunction SendEmailViaACT(ByVal HostApplication As Act.UI.ActApplication, _

ByVal cContact As Act.Framework.Contacts.Contact, _

ByVal sMessageBody AsString, _

ByVal sEmailSubject AsString, _

ByVal ACTHistType AsObject, _

ByVal lReturnReceipt AsBoolean, _

ByVal sAttachments AsString, _

ByVal lIsPrivate AsBoolean, _

ByVal lPreview AsBoolean, _

ByVal EmailAddressField() AsString) AsBoolean

       

Try

If cContact IsNothingThen

LogError.Write(New System.Exception("EmailDocument: Contact can not be empty"), "EmailDocument: Contact can not be empty")

ReturnFalse

EndIf

           

Dim mFilesToAttach = New System.Collections.Specialized.StringCollection()

           

If sAttachments = String.Empty Then

                mFilesToAttach = Nothing

Else

                mFilesToAttach.Add(sAttachments)

EndIf

 

           

''------------------------------------------------------

'' Are we previewing before sending the email

''------------------------------------------------------

           

If lPreview = TrueThen

                HostApplication.UIEmailManager.CreateEmailDraft(cContact, _

                                  "FIELDNAME", _

                                                                 sMessageBody, _

                                                                     sEmailSubject, _

                                                                  ACTHistType, _

                                                                  lReturnReceipt, _

                                                                 mFilesToAttach)

           

Else

                HostApplication.UIEmailManager.SendEmailToContact(cContact, _

                                                                  sMessageBody, _

                                                                  sEmailSubject, _

                                                                  ACTHistType, _

                                                                  lReturnReceipt, _

                                                                  lIsPrivate, _

                                                                  mFilesToAttach, _

                                                                EmailAddressField)

           

EndIf

           

ReturnTrue

       

Catch ex As System.Exception

     LogError.Write(ex, "MergeTemplate:EmailDocument")

EndTry

       

Return False

   

EndFunction

 

Hope this helps

-- Jim Durkin

www.durkincomputing.com

Copper Super Contributor
Posts: 478
Country: Australia

Re: How to add new history Items to selected companies in VB

Thanks Jim

 

It will take me a while to get my head around all of that, this is the first bit of VB code i have ever done Smiley Happy

(i have included my code below, it was cobbled together form several internet sources) and works well, except for it does not fire before the Act widget does. You can even see it on a particularly large email the Act Widget icon appears in the Windows Tray before it disapears

 

I would rather not cross over to Act Mail if it can be helped thats why i was thinking about adding VB code to put a history/note/activity into Act along the same lines as the bit it writes at the bottom of the email, so basically there is a record of what attachements have been sent to a client

 

 

_________________

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim Atmt As Attachment
Dim Mensaje As Outlook.MailItem
Dim Adjuntos As String
Dim Body As String
Dim i As Integer


Set Mensaje = Application.ActiveInspector.CurrentItem
Mensaje.BodyFormat = olFormatHTML

Body = Mensaje.HTMLBody

i = 0
Adjuntos = ""

For Each Atmt In Mensaje.Attachments
    'If Atmt.Size > 5 Then
    Adjuntos = Adjuntos & "<font color=#01325D size=2>** Attached file: <u> " & Atmt.FileName & " </u></font> <br>"
    i = i + 1
    'End If
Next Atmt

Adjuntos = "<u> <b> <font color=#DA5905 size=2> Total number of attached files: " & i & "</font></u></b> <br>" & Adjuntos

Mensaje.HTMLBody = Left(Body, InStr(Body, "</body>") - 1) & Adjuntos & Right(Body, Len(Body) - InStr(Body, "</body>") + 4)

Set Mensaje = Nothing

End Sub

 


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