Answered by:
How to set value for lookup field

Question
-
Hi,
How to set value to lookup field using JavaScript.
function Set()
{
var value = new Array();
var value = new Object();
value[0].id = "f1aa7de1-d1110-e311-b21f-984be16dae07";
value[0].name = "Richard Knox";
value[0].entityType = "EntityReference";
Xrm.Page.getAttribute("new_test_user").setValue(value);
}i used this method but its not working,
and let me know what to write in value[0].entityType= ?
Thanks,
Ketan.
Monday, May 12, 2014 4:07 AM
Answers
-
Hi,
Make sure you are using correct id and try to debug your code,
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Marked as answer by Ketan Pimple Monday, May 12, 2014 11:46 AM
Monday, May 12, 2014 6:57 AMModerator -
function Set()
{
var v = new Array();
var v[0] = new Object();
v[0].id = "f1aa7de1-d1110-e311-b21f-984be16dae07";
v[0].name = "Richard Knox";
v[0].entityType = "systemuser";
Xrm.Page.getAttribute("new_test_user").setValue(v);
}
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Guido PreiteMVP Monday, May 12, 2014 9:54 AM
- Marked as answer by Ketan Pimple Monday, May 12, 2014 11:44 AM
Monday, May 12, 2014 9:54 AM
All replies
-
value[0].entityType = "EntityReference"; // this should your entity name, for example you are trying to set user lookup so it should be
value[0].entityType = "systemuser";
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Proposed as answer by HIMBAPModerator Monday, May 12, 2014 4:17 AM
Monday, May 12, 2014 4:17 AMModerator -
Still Not working.
I have tested through 100 times with changing values and all.
Still it wont set when i click for save.
function OnSave()
{
var a =Xrm.Page.data.entity.attributes.get("ava_address1_usstate").getValue();
var b=Xrm.Page.getAttribute("ava_areacode").getValue();
var c =Xrm.Page.data.entity.attributes.get("ava_annualrevenue").getValue();
if(a==38&&b==302&&c==8)
{
//alert("Condition working");
Set();
}
}
function Set()
{
var v = new Array();
var v[0] = new Object();
v[0].id = "f1aa7de1-d1110-e311-b21f-984be16dae07";
v[0].name = "Richard Knox";
v[0].entityType = "systemuser";
Xrm.Page.getAttribute("new_test_user").setValue(v);
}Please let me know where i am wrong.
Thanks,
Ketan
Monday, May 12, 2014 5:36 AM -
Still Not working.
I have tested through 100 times with changing values and all.
Still it wont set when i click for save.
function OnSave()
{
var a =Xrm.Page.data.entity.attributes.get("ava_address1_usstate").getValue();
var b=Xrm.Page.getAttribute("ava_areacode").getValue();
var c =Xrm.Page.data.entity.attributes.get("ava_annualrevenue").getValue();
if(a==38&&b==302&&c==8)
{
//alert("Condition working");
Set();
}
}
function Set()
{
var v = new Array();
var v[0] = new Object();
v[0].id = "f1aa7de1-d1110-e311-b21f-984be16dae07";
v[0].name = "Richard Knox";
v[0].entityType = "systemuser";
Xrm.Page.getAttribute("new_test_user").setValue(v);
}Please let me know where i am wrong.
Thanks,
Ketan
- Merged by HIMBAPModerator Monday, May 12, 2014 6:43 AM duplicate
Monday, May 12, 2014 5:50 AM -
Hi,
Make sure you are using correct id and try to debug your code,
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Marked as answer by Ketan Pimple Monday, May 12, 2014 11:46 AM
Monday, May 12, 2014 6:57 AMModerator -
function Set()
{
var v = new Array();
var v[0] = new Object();
v[0].id = "f1aa7de1-d1110-e311-b21f-984be16dae07";
v[0].name = "Richard Knox";
v[0].entityType = "systemuser";
Xrm.Page.getAttribute("new_test_user").setValue(v);
}
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Guido PreiteMVP Monday, May 12, 2014 9:54 AM
- Marked as answer by Ketan Pimple Monday, May 12, 2014 11:44 AM
Monday, May 12, 2014 9:54 AM -
Hi,
I have done that task successfully.
Before read your comments i had solved but thanks for valuable replies.
Thanks,
Ketan.
Monday, May 12, 2014 11:45 AM