Integrating Dynamics CRM with an External Source to Trigger Workflows

Scenario:

Imagine a scenario where you want to trigger an existing workflow or a custom action from a webpage located outside the CRM Dynamics environment, such as MS CRM 2011-2013-2015-2016 and 365.

Potential Solution:

One possible solution could be to create a controller page within the CRM context that is accessible from the web. This controller page would utilize JavaScript to execute a REST call based on input parameters provided. By doing so, the controller page can effectively trigger the desired workflow or custom action.

Do you think this approach is viable? Are there any alternatives you would suggest for implementation?

Thank you in advance!

Answer №1

If you have the necessary resources available, you have the option to establish a service using the methods outlined below and then utilize ajax for it.

private static void ExecuteWorkflow(Guid workflowId, Guid entityId)
    {
        try
        {
            string url = ConfigurationManager.ConnectionStrings["crm"].ConnectionString;
            ClientCredentials cc = new ClientCredentials();
            cc.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            OrganizationServiceProxy _service = new OrganizationServiceProxy(new Uri(url), null, cc, null);

            ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
            {
                WorkflowId = workflowId,
                EntityId = entityId
            };

            ExecuteWorkflowResponse r = (ExecuteWorkflowResponse)_service.Execute(request);
            _service.Dispose();
        }
        catch (Exception ex)
        {
            //Handle Exception
        }
    }

If it's not feasible to have the service hosted on the same domain as the CRM server, you can consider impersonation as an alternative.

cc.Windows.ClientCredential.Domain = "DOMAIN";
cc.Windows.ClientCredential.Password = "PASSWORD";
cc.Windows.ClientCredential.UserName = "USERNAME";

You can access more detailed information here.

Answer №2

To trigger a workflow using JavaScript, you can follow these steps:

First, obtain the workflowId by specifying its name and type definition.

    var entityId = // Insert Entity GUID here
    var workflowId = // Insert Workflow GUID here
    var url = // Your organization's root URL
    var orgServicePath = "/XRMServices/2011/Organization.svc/web";
    url = url + orgServicePath;
    var request;
    request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
        "<s:Body>" +
        "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
        "<request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">" +
        "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">" +
        "<a:KeyValuePairOfstringanyType>" +
        "<c:key>EntityId</c:key>" +
        "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + entityId + "</c:value>" +
        "</a:KeyValuePairOfstringanyType>" +
        "<a:KeyValuePairOfstringanyType>" +
        "<c:key>WorkflowId</c:key>" +
        "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + workflowId + "</c:value>" +
        "</a:KeyValuePairOfstringanyType>" +
        "</a:Parameters>" +
        "<a:RequestId i:nil=\"true\" />" +
        "<a:RequestName>ExecuteWorkflow</a:RequestName>" +
        "</request>" +
        "</Execute>" +
        "</s:Body>" +
        "</s:Envelope>";

    var req = new XMLHttpRequest();
    req.open("POST", url, false);
    // Return responses in XML format, as JSON is not supported.
    req.setRequestHeader("Accept", "application/xml, text/xml, */*");
    req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
    req.send(request);

If the request returns status 200, it means the request was successful. This code was tested on a CRM2011 environment.

It is advisable to create a WCF rest or web API, referencing the IOrganizationService, and utilizing CRM service operations through an intermediate WCF rather than directly accessing IOrganizationService.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to determine the number of duplicate items in an Array

I have an array of objects that contain part numbers, brand names, and supplier names. I need to find a concise and efficient way to determine the count of duplicate objects in the array. [ { partNum: 'ACDC1007', brandName: 'Electric&apo ...

Tips on preventing a lone track in Laravel for Server Sent Events

In my Laravel app, I am exploring the use of Server Sent Events. The issue I have encountered is that SSE requires specifying a single URL, like this: var evtSource = new EventSource("sse.php"); However, I want to send events from various parts/controlle ...

A JavaScript function that produces an array as an output

Could anyone explain why the output vector from the function TriangulosParaLinhas is not being stored in the vector Lines? if (lineMode == true) { var lines = triangulosParaLinhas(vertices); } function triangulosParaLinhas(vertices) { var poi ...

Having trouble retrieving data in Next.js and passing it to client components. It's just not functioning as expected

After asynchronously fetching data, I am passing it to a client component as props. However, the state of the client component is not being properly set and displayed. The props are passing correctly, but the state seems to not update for some reason. Ser ...

passport.js and express.js working together to seamlessly redirect users back to the original page after completing oauth authentication

How can I navigate users to the same page after an OAuth request to Twitter by setting a session variable? Here is how the routes are currently configured: // Authentication routes (function () { app.get('/auth/twitter', passport.authentica ...

Is it possible for a div with fixed position to still have scrolling functionality

My fixed positioned div (#stoerer) appears to be moving while scrolling, although it is just an optical illusion. Check out this visual explanation: view gif for clarification Below is the code snippet in question: <div id="stoerer"> <button ...

Delete the file containing Mongoose references

I'm facing an issue with deleting questions when a survey is deleted in the Survey model. Even after deleting the survey, the question remains intact in the database. Survey Schema: let surveyModel = mongoose.Schema( { Title: String, T ...

Incorporating the Material UI App Bar alongside React Router for an enhanced user

For my web development course project, I am venturing into the world of JavaScript and React to create a website. Utilizing Material UI's appbar for my header design, I have successfully incorporated react router to enable navigation on my site. Howev ...

Discovering necessary information by iterating through JSON

Being new to vue js, my goal is to loop through the provided JSON data and check if the required data is present within the file. Here is a snippet of the JSON: [ { "id": "text-5", "widget": "hello", "params": { "0": "section-right", ...

Can you please provide a method for determining which characters are adjacent to each other

I am in the process of developing a markdown editor and I require a check to identify if adjacent characters are specific characters, removing them if they match or adding them otherwise. For example, if the selected text is surrounded by two asterisks li ...

The error message that you are seeing is indicating that the `contracts` property of `this.state

Despite having encountered this issue before, I am still struggling to find a solution. The code snippet for fetching data is as follows: async componentDidMount(){ try { const res = await fetch('https://example.com/data.json'); ...

Use jQuery to dynamically update a text field within a table row based on a selection from

My understanding of JS and jQuery is not very strong. This is the HTML Output I created using a foreach-loop: $('#ProjectOfferPosition0IsystemTypeVariantId').on('change', function () { var prices = []; prices[1] = 500.00; ...

Getting a vnode from a DOM element in Vue 3.0: A Step-by-Step Guide

My question pertains to obtaining a vnode through accessing the DOM using document.getElementById(id). How can I accomplish this? ...

Is there a way to automatically scroll the parent page's top when the user navigates within an iframe?

We are encountering an issue with the loading of the iFrame. When the iFrame loads on the client's page, we notice that the page location jumps around and, in most cases, the page focus is lower down the page. This requires users to scroll up to view ...

The backface remains visible despite being designated as "hidden"

I have successfully created a "flip card" in CSS3, where the card flips downward to reveal the other side when a user hovers over it. I have ensured that the back face is not visible by setting backface-visibility to hidden. However, despite my efforts, th ...

What is the best way to attach an onClick event to a PHP-generated link?

Currently, I'm attempting to implement an onclick event on a link within a PHP file. $body2 .= '<td class="sampling-list-td download-link">' . '<a ' . 'class="sampling-list-download" ' . 'href="#" ' . ...

What is the method for determining the dimensions of the rectangle that the camera can capture at a specific location?

In my latest project, I developed a small three.js application that showcases the movement of multiple circles from the bottom to the top of the canvas: let renderer, scene, light, circles, camera; initialize(); animate(); function initialize() { re ...

Save the value of a promise in a variable for future use in state management within a React-Native application

let storage = AsyncStorage.getItem('@location_data').then(data => data) const MainApp = () => { let [currentLocation, setCurrentLocation] = useState(storage); The current situation is that the storage variable holds a promise. How can ...

What strategies can be implemented to improve the load time for bigvideo.js?

Why are my load times extremely slow for such a small site? I had hoped to display an image before the video loads, but they both seem to load simultaneously, even if the video takes forever to load. This is my HTML: <div id="bigvid"> <div cla ...

Dealing with an overflow of Redis clients in NextJS: Simplifying the process with just one client

Introduction Hello there! I have developed a new app for a discord web-dashboard and utilized redis as my database. The main Issue Whenever I send an axios request to one of the documents in the api folder, which requires a redis client, a new redis cl ...