In certain cases, there’s a need to open a new form filled with prepopulated data, which could be derived from a parent record or set to specific default values. The NavigateTo method is designed to streamline this process, allowing for seamless navigation to a chosen table list, table record, HTML web resource, or custom page, thereby improving the user experience in the Unified Interface. Among the myriad navigation possibilities this method offers, the focus here is on navigating to a new form that comes pre-filled with data.
Click on the NavigateTo link to access comprehensive documentation for the method.
According to the documentation, to open a form in create mode, it is recommended to use the following code.
var pageInput = {
pageType: "entityrecord",
entityName: "account"
};
var navigationOptions = {
target: 2,
height: {value: 80, unit:"%"},
width: {value: 70, unit:"%"},
position: 1
};
Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
function success(result) {
console.log("Record created with ID: " + result.savedEntityReference[0].id +
" Name: " + result.savedEntityReference[0].name)
},
function error() {
// Handle errors
}
);
Enhancing the existing code by incorporating the data parameter into the pageInput parameter will enable the automatic population of required data when the creation form loads.
var pageInput = {
pageType: "entityrecord",
entityName: "account",
data: {
name: "Diddly Squat Farm Shop",
telephone1: "+61 4 1234 5678",
primarycontactid: "e9b3a3cf-7c45-435d-b1a1-f93a3c5139f3",
primarycontactidname: "Jeremey Clarkson"
}
};
var navigationOptions = {
target: 2,
height: {value: 80, unit:"%"},
width: {value: 70, unit:"%"},
position: 1
};
Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
function success(result) {
console.log("Record created with ID: " + result.savedEntityReference[0].id +
" Name: " + result.savedEntityReference[0].name)
},
function error() {
// Handle errors
}
);
