Search code examples
javascriptdynamics-crmdynamics-365

Redirecting to newly created Dynamics 365 record after created by workflow


I have a requirement to create a 'contract' record after opportunity status = won which is done via workflow.

To my knowledge, once the contract is created via workflow, the contract record is saved.

I created the following javascript to run onSave event in contract form properties:

function OnSave(){
var contractId = Xrm.Page.data.entity.getId();
Xrm.Utility.openEntityForm("contract",contractId);
}

However this is not working as expected. Any clue why and any recommendations on a better way of doing this?


Solution

  • CRM UI is client side flow and Workflow is server side logic execution flow. The client can trigger some workflow instances but not going to wait for return handshake unless you are doing custom scripting on custom button click event.

    I would suggest you to use custom action which can return parameters ex. Created contract record GUID, after executing the custom action from client Javascript function - you can open the new contract using your above same code snippet. Even custom workflow activity will do the same but custom action is recommended.

    Call Global Custom Action using JavaScript in Dynamics 365