Solved

CRM 4.0; Need help with using Javascript to call a workflow.

Posted on 2010-08-20
4
981 Views
Last Modified: 2013-11-24
Hi All

I am trying to use Javascript to call a workflow. I have copied the code from a CRM blog;

/* the function */
ExecuteWorkflow = function(entityId, workflowId)
{
var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
" <soap:Body>" +
" <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <Request xsi:type=\"ExecuteWorkflowRequest\">" +
" <EntityId>" + entityId + "</EntityId>" +
" <WorkflowId>" + workflowId + "</WorkflowId>" +
" </Request>" +
" </Execute>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
return(resultXml.xml);
}

/* call */
var theWorkflowId = "<my workflow id>"; //change to your workflow Id
ExecuteWorkflow(crmForm.ObjectId, theWorkflowId);

I am the owner of the workflow and have the top level security role with full rights to everything.

The workflow is set to run 'On Demand', the scope is set to organisation.

I have tried testing this code in the onChange event of a text box and in the onClick function of a button on the form.

I have tried using the workflow id of other workflows I know are working.
....and still nothing.

Can anybody think of some step that I'm missing or some way of debugging the code to see what the problem is.

The only thing that I can see that is out of the ordinary is that the workflow has multiple entries in [dlrcc_MSCRM].[dbo].[workflowbase] whereas other workflows just have one. I have tried each workflowid listed against it.

Thanks.
0
Comment
Question by:abaines
  • 3
4 Comments
 
LVL 29

Expert Comment

by:feridun
Comment Utility
Let's get some basics out of the way:

Is the workflow published, does it do the right things if you run it manually?
What error are you getting, if anything?

0
 

Author Comment

by:abaines
Comment Utility
The workflow is published and I ran it manually against one case successfully.
No error msg at all. When I check the system jobs of the workflow after running the code, there is nothing there.

Thanks
0
 

Accepted Solution

by:
abaines earned 0 total points
Comment Utility
Java solution used
0
 

Author Closing Comment

by:abaines
Comment Utility
Question submitted by a colleague and problem was solved inhouse
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Note: You must have administrative privileges in order to create/edit Sharing Rules. Salesforce.com (http://www.salesforce.com) (SFDC) is a cloud-based customer relationship management (CRM) system. It is a database most commonly used by sales an…
Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now