Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

I am not able to register custom work flow

Posted on by 12,070 Super User 2024 Season 1

Hi all,

I am using this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using System.Activities;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;//RetrieveRequest naemspace
using Microsoft.Crm.Sdk.Messages;
using System.ServiceModel.Description;

namespace Test
{
public class RoundRobinLeadAssignment : CodeActivity
{
protected override void Execute(CodeActivityContext context)
{
ITracingService tracingService = context.GetExtension<ITracingService>();
IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);

//My cystom logic here
}
}
}

Reference below sdk asseblies:

Microsoft.Crm.Sdk.proxy

Microsoft.Xrm.Sdk

Microsoft.Xrm.Sdk.Workflow

use IL merging for reference assemblies.

When I try to register my assembly I have the below error:

3312.Untitled1.png

I tried the link which is provided by  Guido Preite for SDK 6.1.1 But this is not available for me and showed following error

4478.Untitled.png

 

What is wrong? 

 

Thank You

*This post is locked for comments

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: I am not able to register custom work flow

    Hi Yvan,

    Make sure you are using right version of Microsoft.Xrm.Sdk. Also if earlier version is already there in the system, try un-registering it first (make sure you have backup of earlier version before un-registering).

    Thanks

    Regards,

    AW

  • yleclerc Profile Picture
    yleclerc 1,545 on at
    RE: I am not able to register custom work flow

    Hi Abdul,

    I'm not a programmer. Someone else prepared the code, but I updated it to add more fields. Basically, the plugin does 2 things:

    1. It copies values from product to opportunity product when a product is added to an opportunity

    2. It sets values default into the opportunity product to ensure calculated fields work well

    Here is the code:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Query;

    namespace ProductCategory

    {

       public class ProductCategory : IPlugin

       {

           public void Execute(IServiceProvider serviceProvider)

           {

               var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

               var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

               var service = serviceFactory.CreateOrganizationService(context.UserId);

               if (context.MessageName != "Create" || context.PrimaryEntityName != "opportunityproduct")

                   return;

               var entity = (Entity)context.InputParameters["Target"];

               if (!entity.Contains("productid"))

                   return;

               var productid = entity.GetAttributeValue<EntityReference>("productid").Id;

               var product = service.Retrieve("product", productid, new ColumnSet("new_categorie"));

               var support = service.Retrieve("product", productid, new ColumnSet("new_tauxsupport"));

               var ps = service.Retrieve("product", productid, new ColumnSet("new_ps"));

               var supportfixe = service.Retrieve("product", productid, new ColumnSet("new_supportfixe"));

               if (!product.Contains("new_categorie"))

                   return;

               entity["new_categorie"] = product["new_categorie"];

               entity["new_tauxsupport"] = support["new_tauxsupport"];

               entity["new_ps"] = ps["new_ps"];

               entity["new_supportfixe"] = supportfixe["new_supportfixe"];

                Decimal decimalMoney = 0;

                entity["new_escomptepsd"] = new Money(decimalMoney);

                entity["new_escomptesupport"] = new Money(decimalMoney);

                entity["new_supportmanuel"] = new Money(decimalMoney);

                int decimalNumber = 0;

                entity["new_escomptepsp"] = new decimal(decimalNumber);

           }

       }

    }

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: I am not able to register custom work flow

    Hi Yvan Leclerc,

    It seems to an argument error. Can you please confirm that you are ok with your input/output arguments that you used in your code?

    Thanks

    Regards,

    AW

  • yleclerc Profile Picture
    yleclerc 1,545 on at
    RE: I am not able to register custom work flow

    Sure! Here it is:

    Unhandled Exception: System.AggregateException: One or more errors occurred.

    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)

    at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)

    at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)

    at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)

    at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)

    at Xrm.Sdk.PluginRegistration.Forms.PluginRegistrationForm.btnRegister_Click(Object sender, EventArgs e)

    Inner Exception: System.ArgumentNullException: Value cannot be null.

    Parameter name: source

    at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate)

    at Xrm.Sdk.PluginRegistration.Forms.PluginRegistrationForm.<>c__DisplayClass13_1.<btnRegister_Click>b__0(CrmPlugin currentPlugin)

    at System.Threading.Tasks.Parallel.<>c__DisplayClass42_0`2.<PartitionerForEachWorker>b__1()

    at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)

    at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object )

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: I am not able to register custom work flow

    Hi Yvan Leclerc,

    Can you please show me the error log?

    Thanks

    Regards,

    AW

  • yleclerc Profile Picture
    yleclerc 1,545 on at
    RE: I am not able to register custom work flow

    Thank you Abdul,

    I tried replacing the references by newer ones, but not luck. I also use the plugin registration tool from XRMToolBox, but still no luck.

    Since I used it in other CRM instances, I exported it in an Unmanaged solution and imported it in my new instance.

    Weirdly enough, now I can update the plugin with no problem. But if I remove it and try to register again, it doesn't work. As long as I can move forward...!

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: I am not able to register custom work flow

    Hi Yvan Leclerc

    Yes, this is my solution.

    Can you please use plugin registration tool from XRM Tool Box? Ithink will solve your problem.

    If you need something more do let me know.

    Thanks

    Regards,

    AW

  • yleclerc Profile Picture
    yleclerc 1,545 on at
    RE: I am not able to register custom work flow

    Hi Abdul,

    How did you resolve your issue? You just replaced 2013 SDK by version 2015?

    I'm getting the same error, but in CRM 2016.

  • Verified answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: I am not able to register custom work flow

    Hi all

    I used CRM 2015 SDK and as per Gopalan Bhuvanesh answer You don't need to do IL merging to add these Microsoft assemblies. I do this. It solved my problem.

    Thank You

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: I am not able to register custom work flow

    Hi Gopalan

    I have this version of CRM as shown below:

    5661.Untitled3.png

    and I dowloaded the following SDK: https://www.microsoft.com/en-us/download/confirmation.aspx?id=40321

    If I do not do ILMerging so What can I do with reference assemblies?

    Thank You

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans