Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

(No Name) displayed in lookup

Posted on by 39
Hi experts
i tired since last week i am  not able to fix my code, iam trying to set lookup filed but its appear as (No Name) and i did alot of workaround on my code and i tired from fix it and display the real name of record in lookup instead of NO NAME
 
This my JS coed
function retrieveOrganizationalUnit() {
    var projectAttribute = Xrm.Page.getAttribute(/msdyn_project/);
    var resourceOrganizationalUnitAttribute = Xrm.Page.getAttribute(/msdyn_resourceorganizationalunitid/);
    // Check if the project attribute is present and contains a value
    if (!projectAttribute || !projectAttribute.getValue() || projectAttribute.getValue().length !== 1) {
        alert(/Please select a project./);
        return;
    }
    var projectValue = projectAttribute.getValue()[0];
    var projectId = projectValue.id;
    var projectName = projectValue.name;
    // Get the current user's information
    var userSettings = Xrm.Utility.getGlobalContext().userSettings;
    var userId = userSettings.userId.replace(/{/, //).replace(/}/, //);
    var userName = userSettings.userName;
    // Construct the FetchXML query
    var fetchXml = `
        <fetch version=/1.0/ output-format=/xml-platform/ mapping=/logical/ distinct=/false/>
            <entity name=/msdyn_projectteam/>
                <attribute name=/msdyn_organizationalunit/ />
                <filter type=/and/>
                    <condition attribute=/msdyn_project/ operator=/eq/ value=/${projectId}/ />
                </filter>
                <link-entity name=/bookableresource/ from=/bookableresourceid/ to=/msdyn_bookableresourceid/ link-type=/inner/ alias=/ai/>
                    <filter type=/and/>
                        <condition attribute=/userid/ operator=/eq/ uitype=/systemuser/ value=/${userId}/ />
                    </filter>
                </link-entity>
            </entity>
        </fetch>`;
    // Execute the FetchXML query using Web API
    Xrm.WebApi.retrieveMultipleRecords(/msdyn_projectteam/, `?fetchXml=${encodeURIComponent(fetchXml)}`)
        .then(function success(results) {
            if (results.entities.length > 0) {
////                var organizationalUnit = results.entities[0][/msdyn_organizationalunit/];
                var organizationalUnit = results.entities[0]._msdyn_organizationalunit_value;
                var organizationalUnitLogicalName = /msdyn_organizationalunit/;
                if (organizationalUnit) {
                    // Set the value of the lookup field
                    resourceOrganizationalUnitAttribute.setValue([{
                        id: organizationalUnit,
                        entityType: organizationalUnitLogicalName
                    }]);
                    // Trigger the onchange event for the lookup field
                    resourceOrganizationalUnitAttribute.fireOnChange();
                } else {
                    alert(/Organizational Unit is empty in the retrieved record./);
                }
            } else {
                alert(/No matching records found./);
            }
        })
        .catch(function error(error) {
            console.error(/Error retrieving data: / + error.message);
        });
}
 
  • z.sam Profile Picture
    z.sam 299 on at
    (No Name) displayed in lookup
    Hi xcrmadmin@bakerti...,
    You can trace your code to see if projectValue.name has a value .
    No Name occurs when you the name attribute of the look up is null. 
     
    Regards

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans