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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer Service forum

Set Lookup Field Value using Javascript

(0) ShareShare
ReportReport
Posted on by

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:
I have the same question (0)
  • Verified answer
    Dynamics365 Rocker Profile Picture
    7,755 on at

    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);

  • LeoAlt Profile Picture
    16,341 Moderator on at

    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

  • bogzero Profile Picture
    30 on at

    This working fine. Thank you!

  • Kranthi Kiran Gullapalli Profile Picture
    105 on at

    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

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 > Customer Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans