I am having an issue with populating a lookup field in my quick view form. I created a custom table for users to subscribe to notifications from Project records in Project Operations. I want users to click a button on the Command Bar where a Quick Create Form will have the Project associated to the form. I created a lookup that points to the project table and developed a plugin to handle this logic. I can confirm that the Plugin is grabbing the appropriate values. I also have a fallback option where if a record already exists with notification settings on the Project for the User creating the record, it will open up their existing record. All of this works. The only part that does not work is when No record exists, the Quick Creat Form should open a new form to register with that pre populated field. It is not pulling over. Does anyone have any insight on this? I am sharing the plugin code below:
function openNotificationSettingsForm(primaryControl) {
var userId = Xrm.Utility.getGlobalContext().userSettings.userId.replace(/{/, //).replace(/}/, //);
var projectId = primaryControl.data.entity.getId().replace(/{/, //).replace(/}/, //);
var entityName = /inotiv_notificationsettings/;
var projectName = primaryControl.data.entity.getPrimaryAttributeValue();
var filter = `_inotiv_project_value eq '${projectId}' and _ownerid_value eq '${userId}'`;
// Check if an existing notification settings record is present for the current user and project
Xrm.WebApi.retrieveMultipleRecords(entityName, `?$filter=${filter}`).then(
function success(result) {
if (result.entities.length > 0) {
// If a record exists, open the existing record
var existingRecordId = result.entities[0].inotiv_notificationsettingsid;
Xrm.Navigation.openForm({
entityName: entityName,
entityId: existingRecordId
});
} else {
// If no record exists, open a new Quick Create form
var parameters = {};
parameters[/inotiv_project/] = [{ id: projectId, name: projectName, entityType: /msdyn_project/ }];
console.log(/Parameters for Quick Create Form:/, JSON.stringify(parameters, null, 2));
Xrm.Navigation.openForm({
entityName: entityName,
useQuickCreateForm: true,
parameters: parameters
}).then(
function success(result) {
console.log(/Quick Create Form opened successfully./);
},
function error() {
console.log(/Error opening Quick Create Form./);
}
);
}
},
function error(error) {
console.log(/Error querying existing notification settings records: /, error.message);
}
);
}
Any help would be much appreciated. Thank you!