web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Convert Web client to custom work flow

(0) ShareShare
ReportReport
Posted on by 12,119 Moderator

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

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I believe you have to do following 3 steps:

    1. Open Visual Studio.

    2. Check this article - msdn.microsoft.com/.../gg334455.aspx

    3. Use info from point 2 to develop own custom workflow activity.

    Good luck!

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Just curious - why you created a new thread instead of continuing conversation in the same thread?

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Andrii Butenko

    I use this link. I stuck on Register and Use a Custom Workflow Activity Assembly. I am getting this error

    28700.2.png

    and I am not able to resolve this issue. May you please point out my mistake.

    Thank you

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

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

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    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
    84,331 Most Valuable Professional on at

    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
    12,119 Moderator on at

    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

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    No messages needed - www.youtube.com/watch

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    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

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans