RSS

K2.ActivityInstanceDestination.User is NULL?????

10 Jun

This one caught me by surprise! I needed to build up a CSV list of email addresses for all previous task owners for an activity, so the simplest way would be to just append the email address each time we get to the task, right? Apparently not.

Here’s my code:

K2.ProcessInstance.DataFields["AllApproversEmailAddresses"].Value = K2.ActivityInstanceDestination.User.Email;

Nothing too complicated. However, running it gave me the dreaded (and oh so informative) “Object reference not set to an instance of an object”. So what’s happening?

Well, it’s actually not that complicated. Basically when you create any activity the default destination rule is “Plan Just Once” (in fact you don’t even have the option of choosing anything else unless you run the Activity wizard in advanced mode.) Anyway, when this option is chosen the destination instance isn’t actually created, which means that K2.ActivityInstanceDestination will always return null.

To get around this issue you will need to do the following:

  • Right-click the activity to open the activity properties.
  • Click on the Destination Rule Options tab, and then click the ‘Back’ button on the wizard.
  • Check the box which says “Run this wizard in advanced mode”, then click “Next”.
  • You’ll see that “Plan per slot (no destinations)” is selected. Choose “All at once” and then click through the rest of the wizard.
  • Deploy and test.

That’s it. Hope that helps someone!

 
6 Comments

Posted by on June 10, 2011 in K2 Workflows

 

6 Responses to K2.ActivityInstanceDestination.User is NULL?????

  1. Ruben

    June 14, 2011 at 8:17 am

    I’ve also had this one. To me, this “feels” like a bug. What do you think?

     
  2. Trent Jacobs

    June 14, 2011 at 12:27 pm

    Hey Ruben,

    Well, there’s always a fine line between a bug and an undocumented feature… 🙂

    I *think* the reasoning behind the decision is performance – if you have a large number of destination users (and therefore slots) and also a large number of data fields you could put a load on the system as well as the log db. I know K2 did a LOT of performance tweaking in the early days and maybe this was one of them. Who knows? But yeah – some documentation on the ‘feature’ would have been nice!

     
  3. Trent Jacobs

    June 17, 2011 at 4:33 pm

    A quick thank you to Carlos who pointed out to me that the default destination rule option is “Plan Just Once”.

     
  4. Jason

    December 22, 2014 at 1:48 pm

    This helped me…even a few years later. Thanks!

     
  5. คลิปโป้

    January 16, 2016 at 11:19 am

    Hello friends, its fantastic article concerning cultureand fully defined, keep it up all the time.

     
  6. หนังโป

    February 3, 2016 at 7:01 am

    WOW just what I was searching for. Came here by searching for คลิปโป๊

     

Leave a Reply

Your email address will not be published. Required fields are marked *