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
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.
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..
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}';
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.
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" xmlns="schemas.microsoft.com/.../Contracts">
<ActivityId>2a459d71-6220-496b-85b1-8a78e543958d</ActivityId>
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
<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>
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
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
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156