Nintex Workflow Activity Template for Visual Studio

Nintex offers some project templates for Visual Studio. One for an activity and one for an action adapter. You can download them from Nintex SDK: Installing and using Visual Studio templates.

I installed and used them to develop a new activity. After creating a new solution with adapter and activity using Namespaces you get a bunch of errors.
My Namespace is “AtiaNuur.NintexWorkflows”. Here are my steps to setup und correct the two projects:

  • Create new Project of type Nintex Adapter
    • Name “AtiaNuur.NintexWorkflows.HelloWorld”
    • Solution HelloWorld
  • Set SolutionId in package to new Guid (Nintex creates allways the same SolutionId)
  • Add Project of Type Nintex Activity using Name “AtiaNuur.NintexWorkflows.HelloWorldActivity”
    • Change default Namespace to “AtiaNurr.NintexWorkflows.HelloWorld
  • In File AtiaNuur.NintexWorkflows.HelloWorldActivity.cs
    • remove Namespace in class Name
    • Also remove Namespace in PropertyDependencies
    • Remove ‘Activity’ from namespace

The File AtiaNuur.NintexWorkflows.HelloWorldActivity.cs should look like this now:
Nintex-Template-Repair

  • In AtiaNuur.NintexWorkflows.HelloWorldDialog.aspx.cs
    • Remove namespace in classname
  • In AtiaNuur.NintexWorkflows.HelloWorldDialog.aspx
    • Shorten Filename
    • Set new filename in NWAFile
    • Set new filename in .aspx prefix tags
    • Remove duplivate namespace in tag Page
  • Add new EmptyElement “NWAFile”
    • Delete Element.xml
    • Move *.nwa file into EmptyElement
    • Set DeploymentType to ElementFile
  • In .nwa File
    • Set Name, Category and Description
    • <ActivityType>AtiaNuur.NintexWorkflows.HelloWorld.HelloWorldActivity</ActivityType> insert Activity classname
    • <ActivityAssembly>AtiaNuur.NintexWorkflows.HelloWorldActivity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=529ebf25b8a73f63</ActivityAssembly> get your own full filename using ILSpy
    • Remove duplicated Namespace in AdapterType
    • Correct icon filenames
    • Correct ConfigurationDialogUrl
  • In package > Advanced
    • Add Activity Assembly
  • In File “AtiaNuur.NintexWorkflows.HelloWorldAdapter.cs”
  • Create Feature according to https://cann0nf0dder.wordpress.com/2013/09/12/nintex-workflow-custom-actions/
    • Add Event Receiver
    • Change NWAFile Name and Path
    • Change Adapter Class Name

Impersonation in CRM Plug-In and Workflow – the easy way

Some time ago I wrote a post about impersonation in dynamics crm plug-ins.

Today I found a much easier solution: use the impersonated organizationService from localcontext.

IOrganizationService service = localContext.OrganizationServiceImpersonated;

Ok, first you have to create this property. Do this in Plugin.cs, which gets generated by Visual Studio. Create the property:

internal IOrganizationService OrganizationServiceImpersonated
{
    get;
    private set;
}

Add the following line to the constructor of LocalPluginContext:

// Use the factory to generate the impersonated Organization Service.
this.OrganizationServiceImpersonated = factory.CreateOrganizationService(null);

Instead of null you can also pass a systemusers GUID. Null will impersonate as systemadministrator.

And when you are just there, also set the ServiceProvider correctly, so that it’s not null. Then the whole constructor looks like this:

internal LocalPluginContext(IServiceProvider serviceProvider)
{
    if (serviceProvider == null)
    {
        throw new ArgumentNullException("serviceProvider");
    }

    // 1. extra line: Set LocalContext ServiceProvider
    this.ServiceProvider = serviceProvider;

    // Obtain the execution context service from the service provider.
    this.PluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    // Obtain the tracing service from the service provider.
    this.TracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    // Obtain the Organization Service factory service from the service provider
    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    // Use the factory to generate the Organization Service.
    this.OrganizationService = factory.CreateOrganizationService(this.PluginExecutionContext.UserId);

    // 2. extra line: Use the factory to generate the impersonated Organization Service.
    this.OrganizationServiceImpersonated = factory.CreateOrganizationService(null);
}

To get impersonated service in Workflows is a little easier:

var serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
var service = serviceFactory.CreateOrganizationService(null);      //Create impersonated service

How to get the assembly public key token using Visual Studio 2012

If you want to register a WorkflowActivity as safe in Webconfig you need the public key token from the dll.

<authorizedTypes>

<authorizedType Assembly=”Testprojekt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b04480df764d9b77″ Namespace=”Testprojekt” TypeName=”*” Authorized=”True” />
</authorizedTypes>

1. On your SharePoint Server in Windows starmenue, open the “Developer Command Promt for VS2012”

2. In commandprompt type “sn -T *path to your dll*”

publicKeyToken

Error occurred in deployment step ‘Install app for SharePoint’: The provided App differs from another App with the same version and product ID

Problem:
Cannot deploy a solution and getting the error: Error occurred in deployment step ‘Install app for SharePoint’: The provided App differs from another App with the same version and product ID.

Solution:
Open the AppManifest.xml in code view and generate a new guid for the app -> Change value of ProductID.