Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm working on a workflow in which I'm calling a custom activity. After the call of the custom activity I'm trying to get properties which have been changed in the custom activity in my UpdateApprovers method.

enter image description here

The problem is that when I'm outside my activity, and try to access some properties of my activity, I don't get the changes I made, I just have the initialization value. This is the declaration of my properties : public static DependencyProperty listEtapeChoisieProperty = DependencyProperty.Register("listEtapeChoisie", typeof(List), typeof(ActivityLibrary.EtapeOuiNon));

    [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
    [BrowsableAttribute(true)]
    [CategoryAttribute("Misc")]
    public List<DefEtape> listEtapeChoisie
    {
        get
        {
            return ((List<DefEtape>)(base.GetValue(ActivityLibrary.EtapeOuiNon.listEtapeChoisieProperty)));
        }
        set
        {
            base.SetValue(ActivityLibrary.EtapeOuiNon.listEtapeChoisieProperty, value);
        }
    }

    public static DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(System.String), typeof(ActivityLibrary.EtapeOuiNon));
    [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
    [BrowsableAttribute(true)]
    [CategoryAttribute("Misc")]
    public String Title
    {
        get
        {
            return ((string)(base.GetValue(ActivityLibrary.EtapeOuiNon.TitleProperty)));
        }
        set
        {
            base.SetValue(ActivityLibrary.EtapeOuiNon.TitleProperty, value);
        }
    }

This is the initialization of my activity

        etapeOuiNon1.listEtapeChoisie = new List<DefEtape>();
        etapeOuiNon1.Title = "Titre";

During the activity I have this code, which update both properties :

    private void choixEtapeOuiNon_ExecuteCode_1(object sender, EventArgs e)
    {
        Title = "new title";
        if (visa)
        {
            foreach (DefEtape etape in EtapeEnCours.EtapeOui)
            {
                listEtapeChoisie.Add(etape);
            }
        }
        else
        {
            foreach (DefEtape etape in EtapeEnCours.EtapeNon)
            {
                listEtapeChoisie.Add(etape);
            }
        }
        visa = false;
        isFinished = false;
    }

And finally in my UpdateApprovers I'm trying to get the changed value :

    private void UpdateApprovers_Execute(object sender, EventArgs e)
    {
        Title = etapeOuiNon1.Title
        foreach (DefEtape etape in etapeOuiNon1.listEtapeChoisie)
        {
            Approvers.Add("test");
            j++;
        }
    }

But doing this, I only have 0 values in listEtapeChoisie, and etapeOuiNon1.Title is still "Titre".

Do you have any ideas how I can make this two activities communicate ? Thanks for the help :)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I've found a way of doing it, but not sure at all it is the good one!

I've put the attribute as a static public attribute, so I can access from the class, and it's the good values ! But please if you know how to do that more properly, tell me :)

EDIT : Ok, totally found what i wanted : using Dependency property as shown here : http://www.universalthread.com/ViewPageArticle.aspx?ID=192

share|improve this answer
    
Static will share the same value for all workflows. Dangerous. And you are right, the DP is what you need. Just beware of the type. The type must be a serializable type (don't try to put SPWeb, SPUser, etc. objects) –  Steve B Jul 31 '12 at 9:28
    
Haha, yep, thanks for the tip, we spent three days without knowing why our worklflow was throwing errors, because we didn't had access to logs. And don't worry I'm not using any no-serializable type object anymore in my life :) ! –  Thoma Bigueres Aug 1 '12 at 9:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.