Asked by:
BPF:How to start a BPF using JavaScript

Question
-
I will check the name of form. if name is A, start BPF1 then start BPF2. juse like that.Tuesday, December 16, 2014 6:38 AM
All replies
-
Hi,
You can check the form name using below code:-
var item = Xrm.Page.ui.formSelector.getCurrentItem();
itemLabel = item.getLabel();
To call a Business Process flow from javascript:
Refer below link:-
http://ankit.inkeysolutions.com/2013/03/dynamics-crm-2011-trigger-workflow-from.html
If you wish to call the business process each time you open the form, then u need to add script in Onload of page.
Else if you want to call only on create then you need to check the form type, follow below link:-
http://thabscrm.com/2012/02/21/crm-2011-javascript-form-types/
Hope this helps!!!
Thanks,
Prasad
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
Tuesday, December 16, 2014 9:41 AM -
Which version of Crm are you using ? Crm 2015 provides access to BPF functionality with JavaScript, but for previous versions it was much more limited
Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
Tuesday, December 16, 2014 9:31 PMModerator -
Hi,
You can check the form name using below code:-
var item = Xrm.Page.ui.formSelector.getCurrentItem();
itemLabel = item.getLabel();
To call a Business Process flow from javascript:
Refer below link:-
http://ankit.inkeysolutions.com/2013/03/dynamics-crm-2011-trigger-workflow-from.html
If you wish to call the business process each time you open the form, then u need to add script in Onload of page.
Else if you want to call only on create then you need to check the form type, follow below link:-
http://thabscrm.com/2012/02/21/crm-2011-javascript-form-types/
Hope this helps!!!
Thanks,
Prasad
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
Thanks, but the link didn't be accessed.
http://ankit.inkeysolutions.com/2013/03/dynamics-crm-2011-trigger-workflow-from.html
Wednesday, December 17, 2014 6:03 AM -
Hi,
Here is the code, which was there in that link:-
function startWorkflow(entityId, workflowProcessId) { 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\">" + Xrm.Page.context.getAuthenticationHeader() + "<soap:Body>" + "<Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + "<Request xsi:type=\"ExecuteWorkflowRequest\">" + "<EntityId>" + entityId + "</EntityId>" + "<WorkflowId>" + workflowProcessId + "</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); }
The function abovewill take two inputs where entityId is the id of the record for which the workflow will execute and workflowProcessId is the id of the workflow which we want to execute.
Thanks,
Prasad
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
- Edited by Prasad Parameswaran Wednesday, December 17, 2014 6:33 AM
Wednesday, December 17, 2014 6:32 AM -
Hi,
Here is the code, which was there in that link:-
function startWorkflow(entityId, workflowProcessId) { 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\">" + Xrm.Page.context.getAuthenticationHeader() + "<soap:Body>" + "<Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + "<Request xsi:type=\"ExecuteWorkflowRequest\">" + "<EntityId>" + entityId + "</EntityId>" + "<WorkflowId>" + workflowProcessId + "</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); }
The function abovewill take two inputs where entityId is the id of the record for which the workflow will execute and workflowProcessId is the id of the workflow which we want to execute.
Thanks,
Prasad
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
Wednesday, December 17, 2014 7:00 AM -
Hi,
You just need to replace the parameters:- i.e. here--> startWorkflow(entityId, workflowProcessId)
You can get the entityId using beloe code:-
var entityId =Xrm.Page.data.entity.getId();
For getting the workflowProcessId refer below link:-
Thanks,
Prasad
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
Wednesday, December 17, 2014 7:15 AM