0
votes

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://docs.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

2
Try using parent.XrmCore.Commands.Open.openNewRecord please.Khadim Ali
Can you add picture of ribbon settings? You uploaded form properties twice.Arun Vinoth - MVP

2 Answers

0
votes

Instead of custom code, why don't you try Map Entity Field feature?

You can map attributes between entities that have an entity relationship. This lets you set default values for a record that is created in the context of another record.

In your scenario, after mapping Account and Price list fields between Account and Order tables, when you will go to the Related > Orders section and try to create an Order from there, those two fields should be pre-filled on the new Order form.

And I think this feature would work also when you have a Orders sub grid on account form and try to create Order from new button on the sub grid.

enter image description here

You may go through the documentation to understand this concept and to check steps to create mapping.

0
votes

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);
});