Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

not able to populate lookup field

Posted on by Microsoft Employee

I am trying to apply an account value to a lookup field I am calling this javascript on page load event of the entity 'testEntity'

my code is 

function setLookupField(){ 
var lookUpData =new Array(); 
var lookUpItem =new Object(); 
lookUpItem.id ='7b624C940A-49FF-E711-80FC-XXXXXXXXXXXX'; 
lookUpItem.name ='myaccountname'; 
lookUpItem.entityType ='account'; 
lookUpData[0]=lookUpItem; Xrm.Page.getAttribute('new_lookupfield').setValue(lookUpData); 
}

It is setting the value on page load but when I save the record it is throwing error, am I doing something wrong?

 

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: not able to populate lookup field

    Thanks a lot Alex, The guid id was incorrect copied extra '7b'. Thanks everyone I never thought I will get these many solutions so quickly.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: not able to populate lookup field

    Actually, your GUID is in the wrong format

    This part: 7b624C940A

    should have 8 characters

    I think you may have copied that extra 7b from the html-encoded string..

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: not able to populate lookup field

    Try adding braces to the guid (but, again, I'm assuming XXXXXX is not, really, part of the Guid:) ):

    lookUpItem.id ='{7b624C940A-49FF-E711-80FC-XXXXXXXXXXXX}';

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: not able to populate lookup field

    Hi Alex the id is correct, I have just replaced few digits with 'X', I have pasted the error log I am getting, I am unable to figure out anything from that log, please verify the log once.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: not able to populate lookup field

    the error log details are

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.FormatException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #E3FC609ADetail:

    <OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance&quot; xmlns="schemas.microsoft.com/.../Contracts&quot;>

     <ActivityId>2a459d71-6220-496b-85b1-8a78e543958d</ActivityId>

     <ErrorCode>-2147220970</ErrorCode>

     <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic&quot; />

     <Message>System.FormatException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #E3FC609A</Message>

     <Timestamp>2018-01-30T12:16:14.16629Z</Timestamp>

     <ExceptionRetriable>false</ExceptionRetriable>

     <ExceptionSource i:nil="true" />

     <InnerFault i:nil="true" />

     <OriginalException i:nil="true" />

     <TraceText i:nil="true" />

    </OrganizationServiceFault>

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: not able to populate lookup field

    All looks good (except for the missing "function", but, from the other post, it seems to be there so might be just a copy-paste error).

    What about the id, though? Is there an account with that id (and I'm guessing you've replaced real id with ... XXXXXXX?)

    Basically, there are no validations on the client side for the id, so you can assign any id there, but, when you try saving the record, you'll get an error

  • Suggested answer
    Jagannath Profile Picture
    Jagannath 545 on at
    RE: not able to populate lookup field

    Hi Shantanuhadap,

    try the following code for set the lookup value.

    and please post your error.

    function setLookupField()

    {

    var lookUpData =new Array();

    var lookUpData[0] =new Object();

    lookUpData[0].id ="7b624C940A-49FF-E711-80FC-XXXXXXXXXXXX";

    lookUpData[0].name ="myaccountname";

    lookUpData[0].entityType ="account";

    Xrm.Page.getAttribute("new_lookupfield").setValue(lookUpData);

    }

    Thanks,

    Jagannath

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: not able to populate lookup field

    Hi shantanuhadap ,

    your code is correct.

    Please post the error details (hi hope before setLookupField you have put "function" word in your code).

    Thanks

    Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

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