web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Why Isn't my Lookup Populating Data using Javascript?

(0) ShareShare
ReportReport
Posted on by 5
Hey All,
 
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!
I have the same question (0)
  • Verified answer
    Ray Profile Picture
    1,537 on at
    The parameter format is not correct. It should be 3 properties in the root object instead of an array property. You can refer below example:
  • danielspillers Profile Picture
    5 on at
    Ray, thank you so much. This example helped me to populate the field properly. You're a lifesaver!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans