Question

I'm creating a custom workflow activity in VS2010 targeting .NET 3.5. The DLL is actually being used in a Microsoft System Center Service Manager custom workflow, but I don't think that is my issue.

I have a public string property, that the user types in the string of what the activity should use. However, when the WF runs, it errors out 'value cannot be null'. I want to target if it is my code or something else.

When we drag my custom activity onto the designer, I'm able to type in the text of the string on the designer for that property.

public static DependencyProperty ChangeRequestStageProperty = DependencyProperty.Register("ChangeRequestStage", typeof(String), typeof(UpdateChangeRequestStage));

    [DescriptionAttribute("The value to set the ChangeRequestStage Property in the ChangeRequest Extension class.")]
    [CategoryAttribute("Change Request Extension")]
    [BrowsableAttribute(true)]
    [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
    public String Stage
    {
        get { return ((String)(base.GetValue(UpdateChangeRequestStage.ChangeRequestStageProperty))); }
        set { base.SetValue(UpdateChangeRequestStage.ChangeRequestStageProperty, value); }
    }

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        EnterpriseManagementGroup emg = CreateEMG();

        //System.WorkItem.ChangeRequest Extension - ClassExtension_928bec0a_cac4_4a0a_bd89_7146c9052fbe
        ManagementPackClass mpcChangeRequest = emg.EntityTypes.GetClass(new Guid("8c6c6057-56ad-3862-47ec-dc0dde80a071"));

        //System.WorkItemContainsActivity Relationship Class
        ManagementPackRelationship workItemContainsActivityRelationship = emg.EntityTypes.GetRelationshipClass(new Guid("2DA498BE-0485-B2B2-D520-6EBD1698E61B"));

        EnterpriseManagementObject changeRequest = null;

        //Loop thru each emo (Change Request in this case), and assign it. There will never be more than 1 emo returned
        foreach (EnterpriseManagementObject obj in emg.EntityObjects.GetRelatedObjects<EnterpriseManagementObject>(executionContext.ContextGuid, workItemContainsActivityRelationship, TraversalDepth.OneLevel, ObjectQueryOptions.Default))
        { changeRequest = obj; }

        EnterpriseManagementObjectProjection emop = new EnterpriseManagementObjectProjection(changeRequest);

        if (emop != null)
        { emop.Object[mpcChangeRequest, "ChangeRequestStage"].Value = Stage; }

        emop.Commit();

        return base.Execute(executionContext);
    }

Since it is getting a 'value cannot be null' error, I'm guessing it's on this line:

emop.Object[mpcChangeRequest, "ChangeRequestStage"].Value = Stage;

I'm going to test and see if hardcoding a value works or not. Any ideas? enter code here

Was it helpful?

Solution 2

I didn't want to leave this question wide open, so I'm updating it as to how I resolved this (a long time ago).

Rather than working with an EnterpriseManagementObjectProjection (emop), I worked with a standard EnterpriseManagementObject (emo). From there, I was able to follow a similar format from above:

ManagementPackClass mpcChangeRequest = emg.EntityTypes.GetClass(new Guid("8c246fc5-4e5e-0605-dc23-91f7a362615b"));
changeRequest[mpcChangeRequest, "ChangeRequestStage"].Value = this.Stage;
changeRequest.Commit();

OTHER TIPS

try this

if (emop != null && emop.Object[mpcChangeRequest, "ChangeRequestStage"] != null)
   emop.Object[mpcChangeRequest, "ChangeRequestStage"].Value = Stage
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top