function openPlanOfActionPage(isNew, customerRecordId, planOfActionRecordId = "") {
// Log whether we're creating a new record or editing an existing one
console.log("Is New Record:", isNew);
// Verify that customerRecordId and planOfActionRecordId are strings
if (typeof customerRecordId !== 'string') {
console.warn("Warning: customerRecordId is not a string. Converting to string:", customerRecordId);
customerRecordId = String(customerRecordId); // Convert to string if needed
}
if (typeof planOfActionRecordId !== 'string') {
console.warn("Warning: planOfActionRecordId is not a string. Converting to string:", planOfActionRecordId);
planOfActionRecordId = String(planOfActionRecordId); // Convert to string if needed
}
// Log the Customer Record ID and Plan of Action Record ID (if editing)
console.log("Customer Record ID (for linking to new record):", customerRecordId);
console.log("Plan of Action Record ID (if editing existing record):", planOfActionRecordId);
// Set up the page input
var pageInput = {
pageType: "custom",
name: "eb_planofaction_1ca91", // Logical name of the custom page
entityName: "eb_planofaction", // Logical name of the Plan of Action table
recordId: isNew ? "" : planOfActionRecordId.replace(/[{}]/g, "") // Only set recordId if editing an existing Plan of Action
};
// If creating a new record, pass the Customer ID as a parameter
if (isNew) {
pageInput.parameters = { customerId: customerRecordId.replace(/[{}]/g, "") };
}
// Log the complete page input object to verify all details
console.log("Page Input Object:", JSON.stringify(pageInput));
// Set up navigation options
var navigationOptions = {
target: 1, // Open in a new page
width: 800, // Set the width of the dialog
height: 600 // Set the height of the dialog
};
// Log the navigation options to ensure they are correctly configured
console.log("Navigation Options:", JSON.stringify(navigationOptions));
// Attempt to navigate to the page
Xrm.Navigation.navigateTo(pageInput, navigationOptions)
.then(function () {
console.log("Navigation to custom page successful.");
})
.catch(function (error) {
console.log("Error navigating to custom page:", error);
});
}
// Usage example: Open a new Plan of Action for a specific Customer
function openNewPlanOfActionForCustomer(executionContext) {
var formContext = executionContext.getFormContext(); // Get the current form context
var customerRecordId = formContext.data.entity.getId(); // Get the Customer record's GUID
// Log to confirm we're opening a new Plan of Action with the correct Customer ID
console.log("Opening new Plan of Action for Customer Record ID:", customerRecordId);
// Open a new Plan of Action and pass the Customer record ID as a parameter
openPlanOfActionPage(true, customerRecordId);
}
// Usage example: Open an existing Plan of Action
function openExistingPlanOfActionForCustomer(planOfActionRecordId) {
// Log to confirm we're opening an existing Plan of Action
console.log("Opening existing Plan of Action with Record ID:", planOfActionRecordId);
// Open an existing Plan of Action by passing the Plan of Action record ID
openPlanOfActionPage(false, "", planOfActionRecordId);
}