2
votes

I am creating a custom workflow that is - Triggered on the create of a record (Custom Activity).

I need to be able to access the data from the Custom Activity above within my Custom workflow but I am have a hard time finding a reference on how to get the information from the newly created record.

Any advice? Thanks in advanced.

Edit:

public sealed class FeeInvoiceGenerator : CodeActivity
{

    [Input("MyFee")]
    [ReferenceTarget("fee")]
    [RequiredArgument]
    public InArgument<EntityReference> SomeFee { get; set; }

    protected override void Execute(CodeActivityContext executionContext)
    {
        ITracingService tracingService = executionContext.GetExtension<ITracingService>(); 
        try
        {
            tracingService.Trace("Creating Invoice for Fee");
            WorkFlowHelper workFlowHelper = new WorkFlowHelper();
            workFlowHelper.debugMessagesOn = true;

            //creates connection info
            InvoiceFeeHelper invoiceFeeHelper = new InvoiceFeeHelper();
            invoiceFeeHelper.ConnectionInfo(workFlowHelper);
            invoiceFeeHelper.CreatingConnection(workFlowHelper, executionContext);

            //initialize other classes
            FeeMaster feeMaster = new FeeMaster();
            InvoiceMaster invoiceMaster = new InvoiceMaster();
            InvoiceFeeMaster invoiceFeeMaster = new InvoiceFeeMaster();

            EntityReference getFee = this.SomeFee.Get(executionContext);

            String feeId = getFee.Id.ToString();


            invoiceFeeMaster.CreateInvoiceFromFee(workFlowHelper, invoiceFeeHelper, invoiceMaster, feeMaster, feeId, executionContext);

        }
        catch (Exception ex)
        {
            throw new NotImplementedException("error occured" + ex.Message);
        }

    }

}

However, I am running into an issue where I cannot access the [Set Properties] within the workflow itself to assign the input. (at least this is what I have seen from other examples online and it is blank for me)enter image description here

I have also tried to use:

IWorkflowContext workFlowContext = workFlowHelper.context.GetExtension<IWorkflowContext>();

            Guid _feeRecordID = workFlowContext.PrimaryEntityId;

in order to get the records Id to no avail. The other portions of my custom workflow work, If I pass in a guid from a 'Fee'(the record I need to grab), everything works great.

Am I doing something wrong?

Second Edit: I needed to restart IIS on the CRM server before it would recognize that there were inputs to be used.

2

2 Answers

2
votes

Couple of ways you could do this:

  1. Use an input parameter to pass all the data you need.
  2. Use an input parameter to pass the ID of the record, and then use the IOrganizationService to retrieve the rest of the data.

Please see Custom Workflow Activities (Workflow Assemblies) for Microsoft Dynamics CRM for examples and further detail.

0
votes

I am not sure what your WorkflowHelper does but you should not really have to use it.

    // Create the context
    var context = executionContext.GetExtension<IWorkflowContext>();
    //primary entityid
    var _feeRecordId = context.PrimaryEntityId