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");
/* Send the XMLHTTP object. */
xmlhttp.send(soapXml);
}
Please help to resolve my issue.
Thank You