I'm attempting to automatically set the process of an Opportunity record to the 'Lead to Opportunity Sales Process'. So far I have tried both Power Automate / Flow and programmatically with Javascript via a web resource on the Form Properties.
Setting Using Javascript
This method works flawlessly on a Lead record, but on an Opportunity I receive the error 'POST /api/data/v9.0/SetProcess 500'
function setBPF(executionContext) { var formContext = executionContext.getFormContext(); console.log("Checking business process flow."); if (formContext.data.process.getActiveProcess()) { console.log("Business process flow found."); var activeProcessID = formContext.data.process.getActiveProcess().getId(); if (activeProcessID.toUpperCase() != "919E14D1-6489-4852-ABD0-A63A6ECAAC5D") { formContext.data.process.setActiveProcess("919E14D1-6489-4852-ABD0-A63A6ECAAC5D", callBackFunction); } else { console.log("Business process flow is already set."); } } else { console.log("Business process flow is NULL."); formContext.data.process.setActiveProcess("919E14D1-6489-4852-ABD0-A63A6ECAAC5D", callBackFunction); } }; function callBackFunction(result) { if (result == "success") { console.log("Business process flow updated."); } else { console.log("Business process flow was not updated."); } };
Setting Using Power Automate / Flow
This method seems to set the Process ID value fine, but when the record is loaded the Lead to Opportunity Sales Process UI is not visible at the top of the record. Further, the above Javascript reports that the activeProcess is still null when applied.
When a new record is created in Dynamics with a type of Lead > Update record 'Process ID' to '919E14D1-6489-4852-ABD0-A63A6ECAAC5D'
I would prefer the first solution, but we often mass-qualify our Leads and so the record is never opened (and thus the Process isn't set). Because of this I would like to use the same logic on an Opportunity, but receive a 500 error:
POST /api/data/v9.0/SetProcess 500