I am trying to create a custom button to batch confirm invoices. From the home grid in my Invoice entity, I am able to navigate to the selected Invoice forms. From there, I would like to get the formContext and use the OOB function to confirm the invoices. How am I able to get the formContext after navigating to the form using Xrm.Navigation? If my button was on the form, I could use the CRM parameter PrimaryControl but I do not believe this will work since the button is on the home grid. Below is my code.
function batchConfirm(selectedItems) {
var length = selectedItems.length;
var x = 0;
for (i = 0; i < length; i++) {
var selectedItem = selectedItems[i];
var id = selectedItem.Id;
Xrm.Navigation.navigateTo({ pageType: "entityrecord", entityName: "invoice", formType: 2, entityId: id }, { target: 1, position: 1, width: { value: 50, unit: "%" } }).then(
function success() {
},
function error() {
// Handle errors
}
);
}
}