Switch Business process flow through java script in Dynamics 365 CRM

In my dynamics 365 CRM, version 9+ and above.
The update of java script to switch business process flows.
We should use Executioncontext.
As per my requirement, I have done as onsave event.

Synatx:
function OnsaveForm(Executioncontext)
{
var formcontext = Executioncontext.getFormContext();
var processId1="";
var processId2="";
if(Xrm.Page.getAttribute("attributen").getValue() != null)
{
formContext.data.process.setActiveProcess(processId1, callbackFunction);
}
else
{
      formContext.data.process.setActiveProcess(processId2, callbackFunction);
}
}
function callbackFunction(response)
{
if (response == "success")
{
alert("BPF changed !!!");
}
else
{
alert("Error changing BPF!!!");
}
}

After binding the java script, we should enable the "Pass Execution Context as first parameters".