none
custom workflow activity not working

    Question

  • I'm getting an error when trying to run my custom workflow activity that I can't seem to figure out.  The error says "The requested record was not found or you do not have sufficient permissions to view it' but I know i have rights to create and view all these record types.  This is my first custom workflow so the answer may be something simple that I'm just missing.  This step is part of a larger workflow.  The workflow already creates an Account, an opportunity and a contact from a lead.  These parts all work fine and do not require any custom coding.  The last step, which I'm trying to accomplish with a custom workflow is to create a customeropportunityrole entity to relate the newly created contact to the newly created opportunity.  Here's my code:

    using System;
    
    using System.ComponentModel;
    
    using System.ComponentModel.Design;
    
    using System.Collections;
    
    using System.Linq;
    
    using System.Workflow.ComponentModel;
    
    using System.Workflow.ComponentModel.Design;
    
    using System.Workflow.ComponentModel.Compiler;
    
    using System.Workflow.ComponentModel.Serialization;
    
    using System.Workflow.Runtime;
    
    using System.Workflow.Activities;
    
    using System.Workflow.Activities.Rules;
    
    using Microsoft.Crm.Workflow;
    
    using Microsoft.Crm.Sdk;
    
    using Microsoft.Crm.SdkTypeProxy;
    
    
    
    namespace CustomWorkflow
    
    {
    
     [CrmWorkflowActivity("Test WorkflowActivity", "Test")]
    
     public partial class Testcc : Activity
    
     {
    
      protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    
      {
    
       //get CRM service context
    
       IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
    
       IWorkflowContext context = contextService.Context;
    
       ICrmService crmService = context.CreateCrmService();
    
       //SendEmail("Context created");
    
    
    
       customeropportunityrole oppRole = new customeropportunityrole();
    
    
    
       //set customer
    
       oppRole.customerid = new Customer();
    
       oppRole.customerid.Value = ContactProperty.Value;
    
       oppRole.customerid.type = EntityName.account.ToString();
    
    
    
       //set opportunity
    
       oppRole.opportunityid = new Lookup();
    
       oppRole.opportunityid.Value = OpportunityProperty.Value;
    
       oppRole.opportunityid.type = EntityName.opportunity.ToString();
    
    
    
       // Assign StatusCode, StateCode
    
       CrmNumber codeNumber = new CrmNumber();
    
       codeNumber.Value = 1;
    
       oppRole.opportunitystatuscode = codeNumber;
    
    
    
       codeNumber.Value = 0;
    
       oppRole.opportunitystatecode = codeNumber;
    
    
    
       //create relationship
    
       Guid id = crmService.Create(oppRole);
    
    
    
       return ActivityExecutionStatus.Closed;
    
      }
    
    
    
      [CrmInput("Contact")]
    
      [CrmReferenceTarget("contact")]
    
      public Lookup ContactProperty
    
      {
    
       get { return (Lookup)GetValue(ContactPropertyProperty); }
    
       set { SetValue(ContactPropertyProperty, value); }
    
      }
    
    
    
      public static readonly DependencyProperty ContactPropertyProperty =
    
       DependencyProperty.Register("ContactProperty", typeof(Lookup), typeof(Testcc));
    
    
    
      [CrmInput("Opportunity")]
    
      [CrmReferenceTarget("opportunity")]
    
      public Lookup OpportunityProperty
    
      {
    
       get { return (Lookup)GetValue(OpportunityPropertyProperty); }
    
       set { SetValue(OpportunityPropertyProperty, value); }
    
      }
    
    
    
      public static readonly DependencyProperty OpportunityPropertyProperty =
    
       DependencyProperty.Register("OpportunityProperty", typeof(Lookup), typeof(Testcc));
    
     }
    
    }
    
    
    
    

    In the workflow I added this step last and set the properties as follows:

    Contact = {Contact(Create a New Contact with information from Lead(Contact)}

    Opportunity = {Opportunity(Create A New Opportunity with information from Lead(Opportunity)}

    **  "Create a New Contact with information from Lead" is my step that creates the Contact

    ** "Create A New Opportunity with information from Lead" is my step that creates the Opportunity

     

    Monday, August 16, 2010 3:12 PM

Answers

All replies