Thanks Andrew!
I think I'm using different GUIDs (or at least fetching everything correctly) but when I look at the field after publishing I only see the later of the two views (Invoices by Billing Account). My code is below (it needs to be cleaned up a bit but hopefully it gets everything correctly).
/*
function addCustomInvoiceView(executionContext)
input - executionContext
output - N/A
description - takes the value entered in the RMA field, Service Account and Billing Account fields to create two customer views
*/
function addCustomInvoiceView(executionContext)
{
let formContext = executionContext.getFormContext(); // get form context
if ( !formContext.getAttribute('po_rma').getValue()[0].name
|| !formContext.getAttribute('po_serviceaccountid').getValue()[0].name
|| !formContext.getAttribute('po_billingaccountid').getValue()[0].name )
{
console.log("One of the following values were not found: RMA #, Service Account and Billing Account");
}
else
{
let viewID = '{00000000-0000-0000-0000-000000000001}'; // dummy GUID
let entityName = 'invoicedetail';
let invoicesServiceAccountName = "Invoices By Service Account";
let invoicesBillingAccountName = "Invoices by Billing Account";
let rmaProductNumber = formContext.getAttribute('po_rmaproduct').getValue()[0].name;
let rmaProductGUID = formContext.getAttribute('po_rmaproduct').getValue()[0].id;
let serviceAccountName = formContext.getAttribute('po_serviceaccountid').getValue()[0].name;
let serviceAccountGUID = formContext.getAttribute('po_serviceaccountid').getValue()[0].id;
let billingAccountName = formContext.getAttribute('po_billingaccountid').getValue()[0].name;
let billingAccountGUID = formContext.getAttribute('po_billingaccountid').getValue()[0].id;
Xrm.WebApi.online.retrieveRecord("msdyn_rmaproduct", rmaProductGUID, "?$select=_msdyn_product_value").then(
function success(result) {
let _msdyn_product_value = result["_msdyn_product_value"];
let _msdyn_product_value_formatted = result["_msdyn_product_value@OData.Community.Display.V1.FormattedValue"];
let _msdyn_product_value_lookuplogicalname = result["_msdyn_product_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
let productGUID = "{" result._msdyn_product_value "}";
let fetchXMLServiceAccount = createFetchXML(rmaProductNumber, productGUID, serviceAccountName, serviceAccountGUID);
let layoutXMLServiceAccount = createLayoutXML();
let fetchXMLBillingAccount = createFetchXML(rmaProductNumber, productGUID, billingAccountName, billingAccountGUID);
let layoutXMLBillingAccount = createLayoutXML();
formContext.getControl('po_custominvoicelinefilterid').addCustomView(
viewID, entityName, invoicesServiceAccountName, fetchXMLServiceAccount, layoutXMLServiceAccount, true);
formContext.getControl('po_custominvoicelinefilterid').addCustomView(
viewID, entityName, invoicesBillingAccountName, fetchXMLBillingAccount, layoutXMLBillingAccount, false);
},
function(error) {
//Xrm.Utility.alertDialog(error.message); // default error.message
console.log(`addCustomInvoiceView/Xrm.WebApi.online.retrieveRecord/error.message: ${error.message}`);
}
);
}
}
function createFetchXML(productNumber, productGUID, accountName, accountGUID)
{
let fetchXML =
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
"";
return fetchXML;
}
function createLayoutXML()
{
let layoutXML =
""
""
""
""
""
""
"";
return layoutXML;
}