Community
Showing results for 
Search instead for 
Do you mean 
Reply

Setting an Activity's Priority

Highlighted
Bronze Elite Contributor
Posts: 2,119
Country: United_Kingdom

Re: Setting an Activity's Priority

Ahh sorry I misunderstood, so you're trying to assign a priority to an Activity instance.

 

So this is basically similar to what you had (it's in C# but you can transcrive to VB.NET) and check if it works ->

 

ACTAppointmentObject.Priority = ACTFM.Activties.GetActivityPriority(StandardActivityPriority.Medium);
ACTAppointmentObject.Update();

Also just ensure that the ACTAppointmentObject object itself isn't null.

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Highlighted
Copper Contributor
Posts: 214
Country: Netherlands

Re: Setting an Activity's Priority

[ Edited ]

Actually, I'm having the same issue Vivek has. Nullref. error when setting activity priority. Activity is NOT null, priority is NOT null.

public ActivityPriority GetActivityPriorityByName(string name)
{
  foreach (ActivityPriority prio in Controller.Instance.ACTFM.Activities.GetActivityPriorities(false))
  if (prio.Name.ToLower().Equals(name.ToLower()))
  return prio;

  return null;
}



try
{
  act.Priority = GetActivityPriorityByName(prio);
}catch(Exception error)
{

// BAM!!

}

 

And it's even stranger: when I set a breakpoint, and I paste "GetActivityPriorityByName(prio)" in the Watch-window before it's executed from the code, it works. But it doesn't right away. And when I try the following to mimic the Watch-window behaviour, it also doesn' work:

 

var tmp = GetActivityPriorityByName(prio);

Thread.Sleep(2000); // EVEN THIS DOESNT HELP
act.Priority = GetActivityPriorityByName(prio);

Greetings,

ACT Certified Consultants
TendenZ
the Netherlands
Highlighted
Copper Contributor
Posts: 214
Country: Netherlands

Re: Setting an Activity's Priority

By the way, the same goes for activity Type. act != NULL, activityType != NULL.

 

public ActivityType getActivityType(string type)
{
ActivityType result = null;
try
{

foreach (ActivityType at in Controller.Instance.ACTFM.Activities.GetActivityTypes(true))//GetActivityTypes()) // 5april 2017: include inactive!
if (at.Name == type)
return at;
}
catch (Exception error)
{ }
return result;
}

try
{ act.Type = getActivityType(activityType); // SAME PROBLEM HERE.
} catch (Exception er) { }
Greetings,

ACT Certified Consultants
TendenZ
the Netherlands
Highlighted
Copper Contributor
Posts: 214
Country: Netherlands

Re: Setting an Activity's Priority

I seem to have solved the issue, and it's strangest solution ...... in the wórld.

 

If i put this:

ActivityPriority dummy = act.Priority; 

before:

act.Priority = GetActivityPriorityByName(prio);

 

it actually works. And the same for activity type.

 

But .. why? Reading a property before being able to set it?

Greetings,

ACT Certified Consultants
TendenZ
the Netherlands
Highlighted
Administrator
Posts: 1,379
Country: United_Kingdom

Re: Setting an Activity's Priority

When I'm implementing your snippet in isolation everything appears to be working fine.

Glad you fixed it, but I couldn't replicate the issue to begin with - very strange.
Highlighted
Copper Contributor
Posts: 214
Country: Netherlands

Re: Setting an Activity's Priority

Strange. Forgot to mention - it's on 20.0.159.0, Update 7. 

Maybe it's database specific (however I have doubts about that - it's the (slightly modified) Act2018 demo).

And Vivek had the same problem, and I vaguely remember having issues with changing activityType on an existing activity before, but that's at least 4 years ago.

Greetings,

ACT Certified Consultants
TendenZ
the Netherlands