Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Find and execute workflow from JS in MS Dynamics CRM 2016

Posted on by 403

Why my script can't working ?

I want to execute workflow via javascript and called on button. but in my script, it can only stop at alert ("2.5");

function test()
{
	alert("1");
	GetBlastCreateWorkflow("Activate form LOO");
}

function GetBlastCreateWorkflow(wfName)
{
	alert("2");
	var serverUrl = Xrm.Page.context.getClientUrl();
	var odataselect = serverUrl + 
	"/xrmservice/2011/OrganizationData.svc/WorkflowSet?$select=WorkflowId&$filter=ActiveWorkflowId/Id ne null and Name eq'" + wfName + "'";
	alert("2,5");
		$.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: odataSelect,
        beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
        success: function (data, textStatus, XmlHttpRequest) {
			RetrieveAndExecuteCreateWorkflow(Entity);
		},
		error: function (XmlHttpRequest, textStatus, errorThrown){
			alert('OData Select Failed:' + odataselect);
		}
	});
	alert("2,75");
}

function RetrieveAndExecuteCreateWorkflow(Entity)
{
	alert("3");
	var objFilteredWF = null;
	objFilteredWF = Entity;
	wfID = "5F808B14-AD18-4AB1-8E6B-A6A6FF399999";
	
	if(objFilteredWF != null && objFilteredWF.result != null && objFilteredWF.result.length != 0 && objFilteredWF.result[0].WorkflowId != null)
	{
		wfID = objFilteredWF.result[0].WorkflowId;
		Process.callWorkflow(wfID,
		Xrm.Page.data.entity.getId()
		);
	}
}

*This post is locked for comments

  • Suggested answer
    Summer Garg Profile Picture
    Summer Garg 585 on at
    RE: Find and execute workflow from JS in MS Dynamics CRM 2016

    Hi Ferdiansah,

    Check this post, To execute workflow using Java-script.....

    crmhub.blogspot.in/.../execute-workflow-using-java-script-MS-Dynamic-CRM.html

  • Suggested answer
    sandeepstw Profile Picture
    sandeepstw 4,601 on at
    RE: Find and execute workflow from JS in MS Dynamics CRM 2016

    Hi,

    Are you still using process.js ? Can you please check in console what errors are logged there? That will be more specific.

    Thanks,

    Sandeep

  • Ferdiansah Profile Picture
    Ferdiansah 403 on at
    RE: Find and execute workflow from JS in MS Dynamics CRM 2016

    I used it once, but it still can not work. This is my script

    Process.callWorkflow("B0612195-40B5-E711-8106-C4346BACAE18",

    Xrm.Page.data.entity.getId(),

     function () {

     alert("Workflow executed successfully");

     },

     function () {

     alert("Error executing workflow");

     });

  • Suggested answer
    sandeepstw Profile Picture
    sandeepstw 4,601 on at
    RE: Find and execute workflow from JS in MS Dynamics CRM 2016

    Hi,

    You are using "Process.callWorkflow" function but looks like not using source library processjs.codeplex.com. This simple JavaScript library allows you to easily call workflows.

    Please verify my answers.

    Thanks,

    Sandeep

  • Suggested answer
    RE: Find and execute workflow from JS in MS Dynamics CRM 2016

    It looks like you are passing parameters to SOAP request ,refer to below post for executing workflow from javascript using SOAP. You are using SOAP request but passing ODATA parameters which is not supported.

    social.microsoft.com/.../how-to-execute-workflow-through-javascript-in-crm-2013

    community.dynamics.com/.../199683

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans