Search code examples
dynamics-crm

Dynamics CRM Getting Account Details


I'm having a problem with the following thing.

In Dynamics CRM I have a Custom Button that created a new Order, the button works great, however, I wanted to make it work as the OOB one and prefilled some of the Account information such as Account Name and Price List (form example).

example

In Ribbon Workbench I've added the following parameter for my button ribbon settins

The next thing that I've done was to create a new Jscript web resource and add the following code.

references: https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/customize-dev/pass-dynamics-365-data-page-parameter-ribbon-actions

Web resource name: new_getorder Code: function XrmCore.Commands.Open.openNewRecord(primaryControl) {

var formContext = primaryControl;

}

I've then added the web resource on the Order form where is supposed to trigger when clicking on the custom button from the account form, but I'm getting a script error (which is not a surprise for me)

form properies

I've also enabled Pass execution context as first parameter Web resource method does not exist: XrmCore.Commands.Open.openNewRecord

new order button from account ribbon

Error when loading the Order form: Web resource method does not exist: XrmCore.Commands.Open.openNewRecord


Solution

  • Anyway, I've managed to find my solution by using this script in a custom web resource

    enter code here
    
    var entityFormOptions = {};
    entityFormOptions["entityName"] = "salesorder";
    entityFormOptions["createFromEntity"] = currentRecordRef;;
    
    // Open the form.
    Xrm.Navigation.openForm(entityFormOptions).then(
    function (success) {
        console.log(success);
    },
    function (error) {
        console.log(error);
    });