Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Convert Web client to custom work flow

Posted on by 12,070 Super User 2024 Season 1

Hi all

I have this code 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using Newtonsoft.Json;

namespace TestForMailChimp
{
class Program
{
static void Main(string[] args)
{
var sampleList = JsonConvert.SerializeObject(
new
{
name = "Sample List",
contact = new
{
company = "MailChimp",
address1 = "675 Ponce De Leon Ave NE",
address2 = "Suite 5000",
city = "zip",
state = "GA",
zip = "30308",
country = "US",
phone = ""
},
permission_reminder = "You'\''re receiving this email because you signed up for updates about Freddie'\''s newest hats.",
campaign_defaults = new
{
from_name = "Freddie",
from_email = "freddie@freddiehats.com",
subject = "MailChimp Demo",
language = "en",
},
email_type_option = true
});
var uri = string.Format("https://{0}.api.mailchimp.com/3.0/lists", "us14");

try
{
using (var webClient = new WebClient())
{
webClient.Headers.Add("Accept", "application/json");
webClient.Headers.Add("Authorization", "apikey " + "ab15c4d132d2aff98b952ca886a92e5a");

Console.WriteLine(webClient.UploadString(uri, "POST", sampleList));
}
}
catch (WebException we)
{
using (var sr = new StreamReader(we.Response.GetResponseStream()))
{
Console.WriteLine(sr.ReadToEnd());
}
}
}
}
}

I want custom workflow for this code. I want this because of my this requirement.

Please do let me know What can I do to solve my problem?

Thank you

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Convert Web client to custom work flow

    Hi guys! You can look at our CTI solution, Tenfold. We integrate MS Dynamics for a more productive sales workflow. Check out the features of a Tenfold integration here: www.tenfold.com/.../dynamics

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Convert Web client to custom work flow

    Obviously it means what it means. CRM can't load mentioned assembly. If you want to use that assembly you will have to combine all your assemblies into one using ILmerge - nicknow.net/dynamics-crm-ilmerge-dll-plugin or use .Net inbuilt assemblies for serialization/deserialization purposes like System.Runtime.Serialization.Json

    Good luck.

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Convert Web client to custom work flow

    Hi Andrii Butenko

    When I run my custom work flow from crm. I have this error. Please help How can I resiolve this issue.

    1134.3.png

    Thank you

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Convert Web client to custom work flow

    Looks like you were able to convert your console app to Custom Workflow Activity that was the main goal of this thread.

    Anyway if you want to fix your next issue you should understand that you are trying to use CRM 4.0 endpoint. Based on your syntax I can assume that you use 2011 or higher that leads to following article that describes how to call workflow from JS with 2011 endpoints - www.mscrmconsultant.com/.../execute-workflow-using-javascript-in.html

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Convert Web client to custom work flow

    Hi Andrii Butenko

    Sorry for disturbing you. I wrote this code to convert my web client to custom work flow

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Activities;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Workflow;

    using System.Net;

    using System.IO;

    using Newtonsoft.Json;

    namespace IntegrateMailChimpWithCRMTest

    {

       public class MailChimpTest : 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);

               var sampleList = JsonConvert.SerializeObject(

           new

           {

               name = "Sample List",

               contact = new

               {

                   company = "MailChimp",

                   address1 = "675 Ponce De Leon Ave NE",

                   address2 = "Suite 5000",

                   city = "zip",

                   state = "GA",

                   zip = "30308",

                   country = "US",

                   phone = ""

               },

               permission_reminder = "You'\''re receiving this email because you signed up for updates about Freddie'\''s newest hats.",

               campaign_defaults = new

               {

                   from_name = "Freddie",

                   from_email = "freddie@freddiehats.com",

                   subject = "MailChimp Demo",

                   language = "en",

               },

               email_type_option = true

           });

               var uri = string.Format("https://{0}.api.mailchimp.com/3.0/lists", "us");

               try

               {

                   using (var webClient = new WebClient())

                   {

                       webClient.Headers.Add("Accept", "application/json");

                       webClient.Headers.Add("Authorization", "apikey " + "ab15c4d1952ca886a92e5a");

                       Console.WriteLine(webClient.UploadString(uri, "POST", sampleList));

                   }

               }

               catch (WebException we)

               {

                   using (var sr = new StreamReader(we.Response.GetResponseStream()))

                   {

                       Console.WriteLine(sr.ReadToEnd());

                   }

               }

           }

       }

    }

    I register it as you showed me the link. I bind this custom workflow with the help of add step in crm's work flow. I call this work flow on button through js. My js code is below. My code is not working as it is worked in web client.  

    function getWorkflowId ()

    {

    debugger;

    var entityId = ""; //Guid of record that workflow is to run on.

    var workflowId = "29D2C96A-72C5-4A6D-85FE-9ADE9921F26C"; //Workflow Guid.

    /*Generate Soap Body.*/

    var soapBody = "<soap:Body>" +

    "  <Execute xmlns='schemas.microsoft.com/.../WebServices&;>" +

    "    <Request xsi:type=\'ExecuteWorkflowRequest\'>" +

    //"      <EntityId>" + entityId + "</EntityId>" +

    "      <WorkflowId>" + workflowId + "</WorkflowId>" +

    "    </Request>" +

    "  </Execute>" +

    "</soap:Body>";

    /*Wrap the Soap Body in a soap:Envelope.*/

    var soapXml = "<soap:Envelope " +

    "  xmlns:soap='schemas.xmlsoap.org/.../&; " +

    "  xmlns:xsi='www.w3.org/.../XMLSchema-instance&; " +

    "  xmlns:xsd='www.w3.org/.../XMLSchema&;>" +

    GenerateAuthenticationHeader() +

    soapBody +

    "</soap:Envelope>";

    /* Create the XMLHTTP object for the execute method.*/

    var serverUrl = Xrm.Page.context.getServerUrl() + "/MSCRMservices/2007/crmservice.asmx";

    var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    xmlhttp.open("POST", serverUrl, false);

    xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    xmlhttp.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute&quot;);

    /* Send the XMLHTTP object. */

    xmlhttp.send(soapXml);

    }

    Please help to resolve my issue.

    Thank You

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Convert Web client to custom work flow

    No messages needed - www.youtube.com/watch

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Convert Web client to custom work flow

    Hi Andrii Butenko

    Sorry for disturbing you one again. I have this code

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Activities;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Workflow;

    using System.Net;

    using System.IO;

    using Newtonsoft.Json;

    namespace IntegrateMailChimpWithCRMTest

    {

       public class MailChimpTest : CodeActivity

       {

           protected override void Execute(CodeActivityContext context)

           {

               var sampleList = JsonConvert.SerializeObject(

           new

           {

               name = "Sample List",

               contact = new

               {

                   company = "MailChimp",

                   address1 = "675 Ponce De Leon Ave NE",

                   address2 = "Suite 5000",

                   city = "zip",

                   state = "GA",

                   zip = "30308",

                   country = "US",

                   phone = ""

               },

               //permission_reminder = "You'\''re receiving this email because you signed up for updates about Freddie'\''s newest hats.",

               campaign_defaults = new

               {

                   from_name = "Freddie",

                   from_email = "freddie@freddiehats.com",

                   subject = "MailChimp Demo",

                   language = "en",

               },

               email_type_option = true

           });

               var uri = string.Format("https://{0}.api.mailchimp.com/3.0/lists", "u");

               try

               {

                   using (var webClient = new WebClient())

                   {

                       webClient.Headers.Add("Accept", "application/json");

                       webClient.Headers.Add("Authorization", "apikey " + "ab15c4d12aff98b952ca886a92e5a");

                       Console.WriteLine(webClient.UploadString(uri, "POST", sampleList));

                   }

               }

               catch (WebException we)

               {

                   using (var sr = new StreamReader(we.Response.GetResponseStream()))

                   {

                       Console.WriteLine(sr.ReadToEnd());

                   }

               }

           }

       }

    }

    What message I use to register this new step. I know this msdn.microsoft.com/.../gg328576(v=crm.5).aspx but I am confusing What message I use.? May you please help me.

    Thank you

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Convert Web client to custom work flow

    Just FYI. Plugin registration tool can be used to register both plugins and custom workflow activities.

    If you anyway want to register custom workflow activities using PowerShell - unfortunately I'm not experienced in it so good luck doing it.

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Convert Web client to custom work flow

    Hi Andrii Butenko

    I need to register workflow not plug in. Am I write this msdn.microsoft.com/.../gg328153(v=crm.5).aspx link tells me that.?

    Thank you

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Convert Web client to custom work flow

    Is there any reason you use powershell to register Custom Worklfow Activity? Try Plugin Registration Tool from SDK.

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans