Search code examples
dynamics-crmribbondynamics-crm-2016crm-ribbon-workbench

How to run two functions from one button in crm


I am using ribbon workbench and I need my customize button to activate two functions :

  1. JS function
  2. save function - that is already used in vanilla save button. In ribbon workbench I connected my js function to my button - it works, to connect the Crm save function : I inserted to Misc > Command core -> this func: Mscrm.SavePrimary

When I click my button the js function works but nothing is saved and I get a massage that my data is not saved, it seems that the crm function: Mscrm.SavePrimary, was fired but wasn't complete.

Is connecting these two functions to one button is possible? If it's possible what is the right way?


Solution

  • The right way would be to use the Save function that is in SDK: https://msdn.microsoft.com/pl-pl/library/gg334720.aspx#Anchor_8

    Xrm.Page.data.entity.save() is equivalent of "Save" command that you have on command bar. What are you currently doing is not supported customization and is likely to stop working after any upgrade of the system

    For people using Dynamics 365 Online version 9.x and later, save function is changed a little bit: https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/formcontext-data/save

    formContext.data.save(saveOptions).then(successCallback, errorCallback);