locked
Status Value in Workflow RRS feed

  • Question

  • Regarding CRM 4.0

     

    I need some help with a custom workflow. I need to figure out how to bring in a status type into a custom workflow activity and I can’t figure it out. I know how to do it with a string.

     

    For example. I want to be able to do various actions based on the status code (such as “active” or “inactive”) or Status Reason of an entity from within the custom workflow code.

     

    For example, I want to be able to do something like:

    If statuscode.value == 0, then…

    If statuscode.value == 1, then…

     

    The problem is I don’t know how to get the statuscode into the code and then be able to use it in logical tests. I tried the code below that can be used to get a string value but it isn't working for a Status value:

     

    public static DependencyProperty statusProperty = DependencyProperty.Register("status", typeof(Status), typeof(ArchiveLinkFolderActivity));

    [CrmInput("Status")]

    public string status

    {

    get

    {

    return (Status)base.GetValue(statusProperty);

    }

    set

    {

    base.SetValue(statusProperty, value);

    }

    }

     

    Does anyone have any suggestions as to how I can get a Status value into a workflow in a format that I can use to do if..then statements with?

     

    Thanks!

    Kyle

    Wednesday, June 25, 2008 11:29 PM

Answers

  • In case anyone needs this in the future, this is what I was looking for:

     

    private int RetrieveStatusInformation(ICrmService service, Guid contactId)

    {

     

    ColumnSet colset = new ColumnSet(new string[] {"statecode"});

    contact cont =(contact) service.Retrieve("contact", contactId, colset);

    if (cont.statecode != null)

    {

    if (cont.statecode.Value == ContactState.Active)

    {

    return 1;

    }

    else

    {

    return 0;

    }

    }

    return 0;

    }

     

     

    Thanks!

    Kyle

    Thursday, July 10, 2008 7:48 PM

All replies

  • Kyle,

     

    With 4.0, you don't have to do a custom workflow assembly to trigger on status change.  standard workflow will work fine.

     

    1. Create a new workflow, set it to trigger when record is created or when record status changes.

     

    Insert a check condition step, something like If Status equals action, then perform action.  Then insert your second check condition step, making sure that you click on the top of the first step, so it inserts it after your first step, not as a sub-step to your first check condition.

     

    You could also use wait for conditions and insert paralell wait branches.  I would probably just use check conditions, since you are triggering it every time that the status changes, it would always run when the users change the workflow status.

    Thursday, June 26, 2008 1:15 AM
    Moderator
  • Good point.

     

    However, I need to do a custom workflow since it triggers some code that does some file system operations. I could create a custom assembly for each status code but this means creating and maintaining more code. This is especially true when dealing that have several status reasons.

     

    Kyle 

    Thursday, June 26, 2008 2:05 AM
  • In case anyone needs this in the future, this is what I was looking for:

     

    private int RetrieveStatusInformation(ICrmService service, Guid contactId)

    {

     

    ColumnSet colset = new ColumnSet(new string[] {"statecode"});

    contact cont =(contact) service.Retrieve("contact", contactId, colset);

    if (cont.statecode != null)

    {

    if (cont.statecode.Value == ContactState.Active)

    {

    return 1;

    }

    else

    {

    return 0;

    }

    }

    return 0;

    }

     

     

    Thanks!

    Kyle

    Thursday, July 10, 2008 7:48 PM