Answered by:
Set Lookup Value Using JavaScript

Question
-
Hello Experts i am setting a lookUp value in Account Entity by using Following Code but the Lookup is not changing What is wrong with this Code. I am using SOAP Request and Getting All Values but unable to Set the Lookup.
Please Suggest.
var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = retrieved.results[0].TerritoryId;
lookup[0].name = retrieved.results[0].Name;
lookup[0].entityType = "account";
Xrm.Page.getAttribute("territoryid").setValue(lookup);I am calling the JS method onChange Event of a field.
Please Suggest
Thank you
saroj
- Edited by Saroj kumar Das Thursday, January 10, 2013 1:50 PM
Thursday, January 10, 2013 1:48 PM
Answers
-
Hi,
Try like as below
var lookup = new Object();
var lookupValue = new Array();
lookup.id = etrieved.results[i].TerritoryId;
lookup.entityType = "territory";
lookup.name = retrieved.results[i].Name;
lookupValue[0] = lookup;
Xrm.Page.getAttribute("territoryid").setValue(lookupValue);but make sure retrieved.results[i].Name and etrieved.results[i].TerritoryId; returning correct values.
Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
Vikram !
- Edited by _Vikram Thursday, January 10, 2013 2:00 PM
- Marked as answer by JLattimerMVP, Moderator Thursday, February 7, 2013 4:55 AM
Thursday, January 10, 2013 1:52 PM
All replies
-
Hi,
Try like as below
var lookup = new Object();
var lookupValue = new Array();
lookup.id = etrieved.results[i].TerritoryId;
lookup.entityType = "territory";
lookup.name = retrieved.results[i].Name;
lookupValue[0] = lookup;
Xrm.Page.getAttribute("territoryid").setValue(lookupValue);but make sure retrieved.results[i].Name and etrieved.results[i].TerritoryId; returning correct values.
Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
Vikram !
- Edited by _Vikram Thursday, January 10, 2013 2:00 PM
- Marked as answer by JLattimerMVP, Moderator Thursday, February 7, 2013 4:55 AM
Thursday, January 10, 2013 1:52 PM -
Hi,
"entityType" needs to be set to the schema name of the "terriroty" not "account" entity.lookup.entityType = "territory";
Vikranth http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"
- Proposed as answer by Vikranth Pandiri Thursday, January 10, 2013 1:56 PM
Thursday, January 10, 2013 1:55 PM -
Hi Vikram Thank you for your Reply. But still it's not working. Please suggest some other solution
Thank you.
saroj
Thursday, January 10, 2013 1:57 PM -
Thank you very Much Vikram. It works great. Thank you again.
saroj
Thursday, January 10, 2013 2:08 PM