Community
Showing results for 
Search instead for 
Do you mean 
Reply

Assigning a custom Activity Type to a new activity

Astute Commentator
Posts: 168
Country: United States

Assigning a custom Activity Type to a new activity

Hi,

 

I hope somebody knows how to assign Activity Types to new activities.

 

I am having problems assigning an existing custom activity type to an ACT! activity. On the example below, I retrieve the ACT! activities and then assign a pre-set activity "Custom1" to the new activity I've just created. However, I always get a "System.NullReferenceException" when I do it. It works if you do the standard ones i.e. Meeting, Todo, etc.. However, if you use any other type, it fails. What am I doing wrong?

 

Any solutions for this would be very welcome.

 

Thanx.

 

T

 

 

            '
            ' Set the Activity Types Array
            '
            ActivityTypesInACT = ACTFM.Activities.GetActivityTypes
            iTotalActivityTypes = UBound(ActivityTypesInACT)

 

           For iCurrentActivityType = 0 To iTotalActivityTypes - 1
                    '
                     ' Go through all the categories for this type and see if there is a match.
                      '
                       If ActivityTypesInACT(iCurrentActivityType).Name = "Custom1" Then
                              On Error Resume Next

                                   '

                                   '  Null Error happens here on the assignments!

                                   '
                               ACTAppointmentObject.Type = ActivityTypesInACT(iCurrentActivityType)
                               If Err.Number <> 0 Then
                                     msgbox( "Error: " & err.description)
                               End If
                               Exit For
                         End If
                    Next

 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Assigning a custom Activity Type to a new activity

Pass your new activity type as a paramter.

 

'//Get pur new activity type

Dim activitytype As ActivityType= Me.HostFramework.Activities.GetActivityType("MyCustomType")

 

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

' Couldn't find it by name then just get the first ActivityType

' User may have deleted it ???
'-------------------------------------------------------------------
If activitytype Is Nothing Then
   activitytype = HostFramework.Activities.GetActivityType(1)
End If

 

'// Schedule a new activity using the new type

ACTApp.UIActivityManager.ScheduleNewActivity(activitytype)

 

Hope this helps

-- Jim Durkin

Astute Commentator
Posts: 168
Country: United States

Re: Assigning a custom Activity Type to a new activity

Thanx for the code snippet.

 

I get a NullReference Error everytime I take a just created activity and do a

    ACTAppointmentObject.Type = MyActivityType

 

That seems to be a bug in ACT!. You can set the activity Type field on an activity template.

 

You can, however, pass the activity type to the create activity function and it does create the activity correctly. Go figure!


So I've coded around the issue and create the proper activity from the very beginning instead of modifying it later.

 

The question still lingers: How can one change the Activity.Type for an existing ACT! activity and ActivityTemplate? The code that I've run always come with a Null Reference on the assignment.

 

T

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Assigning a custom Activity Type to a new activity

[ Edited ]

I looked at some of my code which is not throwing an error. I have a dropdown which I populate using GetActivityTypes.

 

cDropDownlist.Items.AddRange(HostFramework.Activities.GetActivityTypes(False))

 

Then on the save event I change the me.activity.type to the selected item in th elist. Has not caused any issues for me.

 

Me.Activity.Type = DirectCast(cControl, Durkin.Common.Classes.CustomControls.DropDownListDurkin).SelectedItem

 

Then last step I update the activity

Me.Activity.Update()

 

Hope this helps

-- Jim Durkin

 

Astute Commentator
Posts: 168
Country: United States

Re: Assigning a custom Activity Type to a new activity

Thanx.

 

That may work with a created activity but it definitely does not work with an activity template. I always get a Null exception.

 

T

------------------------------------

 

        Dim ACT_ActivitytTemplate As Act.Framework.Activities.ActivityTemplate

        Dim  ActivityTypesInACT() As Act.Framework.Activities.ActivityType

        ACT_ActivitytTemplate = ACTFM.Activities.CreateActivity(Act.Framework.Activities.StandardActivityType.Meeting)

       

        ActivityTypesInACT = ACTFM.Activities.GetActivityTypes

        iTotalActivityTypes = UBound(ActivityTypesInACT)

        For iCurrentActivityType = 0 To iTotalActivityTypes - 1
         '
         ' Go through all the categories for this type and see if there is a match.
         '
           If UCase(ActivityTypesInACT(iCurrentActivityType).Name) = UCase("Custom1") Then

               ACT_ActivitytTemplate.Type = ActivityTypesInACT(iCurrentActivityType)

          End if
       Next
      

 

 

 

 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Assigning a custom Activity Type to a new activity

Why do you need to use an activity template? rather then an activity?

 

-- jim

Astute Commentator
Posts: 168
Country: United States

Re: Assigning a custom Activity Type to a new activity

When creating activities in ACT! using the ACT! Framework, you need to use first the Activity Template to create it. WHY? Don't know, but that's the only way we have been able to properly create an activity and perform the necessary assignments (other than type) to make it point and work the correct way.

 

I have resolved the problem where instead of changing the activity template's Type, I create the activity with the correct type from the very begging (since changing it fails). Kind of painful but at least it works.

 

It's one of those idiosyncracies with the ACT! SDK. Really simple stuff that should work just does not.

 

C'est la vie.

 

T