Scenario
I have two entities. One is a custom entity called Event Requests, which has a 1:N relationship (respectively) with the Appointment entity.
In the Event Requests form, I have a sub-grid that is connected to the Appointment entity, were I would like the user to create Appointment records that are under the created Event Request record. If the user clicks on the OOB (Out of Box) New button on the grid, it will open a main form (in full screen), with the Regarding field and Event Request lookup field pre-populated with the Event Request record. I believe this logic is already implemented through the 1:N relationship.
What I am trying to do is configure it so that when a user clicks on the new button in the sub-grid, it opens the Appointment form in a dialog window (instead of full screen) and the form will also have the Regarding field and Event Request lookup field pre-populated (and hidden) with the Event Request record (similar to how the OOB New button works). I first thought of using a quick create form as a possible solution, because it would auto-populate the desired lookup fields, but the quick create form has limitations. The limitations that I am facing is the general UI of the form as well as having additional sub-grids on the form.
What I have done so far is that I have created a custom button, where I have incorporated the following JS code to open the form in a dialog:
Custom Button Creation Method
Java Script to Open the Form
function OpenMbrEventRequestPage() {
// Centre Dialog
var pageInput = {
pageType: /entityrecord/,
entityName: /appointment/,
formType: 2,
};
var navigationOptions = {
target: 2,
width: {value: 70, unit:/%/},
position: 1
};
Xrm.Navigation.navigateTo(pageInput, navigationOptions);
}
Issue
The issue that I am facing is that the code above just opens a new appointment record, with none of the fields pre-populated. I have tried the following methods in order to have the desired Lookup fields populated with the Event Request record, but I could not get the fields to be populated:
Background Workflow
I created a background workflow to be triggered, when a new appointment record has been created. In the workflow, I have stated a condition that if the Event Request choice field is /Yes/, then the Regarding field and Event Request lookup field will be populated with the Event Request dynamic record (Entity: Event Request, Attribute: Event Request)
Mapping
I accessed the Mapping section, where I created new field mapping for the Regarding field and Event Request lookup field
Incorporating Custom JavaScript
I am still fairly new to JavaScript, but I did some research online to see if anyone has had the similar issue and resolved it with creating custom JS code. I found a number of postings and tried to apply it to my scenario, with no success. I also tried reviewing the Microsoft documentation to see if there are any solutions, but I couldn't find anything that would help.
Request
Any ideas on how to resolve this with a possible solution? If this solution requires a custom JavaScript code, can you please show me the code as I am fairly new to JS.
Any assistance that you can provide would be greatly appreciated.
Thank you
Sanjaya