Skip to main content

Notifications

Announcements

No record found.

Customer Service forum

Set Lookup Field Value using Javascript

Posted on by Microsoft Employee

Hi,

I am getting the below mentioned error while setting value on lookup field from account entity. Please have a look on it.

"UciError: Value should be of type: LookupValue[] with valid entity type.Entity type "account" is invalid." 

I have used Xrm.Page.getAttribute(FiledName).setValue(lookupObjectValue);

Categories:
  • RE: Set Lookup Field Value using Javascript

    Please the article which i have written, It gives complete details on how to set and why we need to set in that way.

    d365learnings.blogspot.com/.../how-to-set-lookup-value-using-javascript-dynamics-crm-portal.html

  • bogzero Profile Picture
    bogzero 30 on at
    RE: Set Lookup Field Value using Javascript

    This working fine. Thank you!

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: Set Lookup Field Value using Javascript

    Hi partner,

    Look up filed is a special field with two properties: Id and Value which makes a little difference between setting value to lookup and other fields.

    So you need to set a lookup object to lookup field.

    In addition, I prefer to use "ExecutionContext.getFormContext().getAttribute(fieldname)" in V9.0.

    You could refer to the following code:

        // GET and SET Lookup / Customer field value
        var functionName = function (executionContext) {
    
            // Access the field on the form
            var field = executionContext.getFormContext().getAttribute("parentaccountid");
    
            // Verify it does exist on the form
            if (field != null) {
    
                // Get its field value; Returns the Lookup object
                var value = field.getValue();
    
                // To get the Id, Name and Entity Name (account/contact)
                var reocord_id = field.getValue()[0].id;
                var record_name = field.getValue()[0].name;
                var record_entityName = field.getValue()[0].entityType;
    
                // Set its field value
                field.setValue([{
                    id: reocord_id,
                    name: record_name,
                    entityType: record_entityName
                }]);
            }
        }


    Hope it helps.

    Best Regards,

    Leo

  • Verified answer
    Dynamics365 Rocker Profile Picture
    Dynamics365 Rocker 7,755 on at
    RE: Set Lookup Field Value using Javascript

    You have to write your code some thing like this:

    var lookupVal = new Array();

       lookupVal[0] = new Object();

       lookupVal[0].id = accountid;

       lookupVal[0].name = accountname;

       lookupVal[0].entityType = "account";

    Xrm.Page.getAttribute(FiledName).setValue(lookupVal);

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans