Answered by:
Jscript: set lookup field

Question
-
Hi,
i want to change the value of a lookup field using jscript.
I already retrieved the giud, and now i want to write this guid to a lookup field.
What is the correct syntax for this task?
crmForm.all.my_lookupfield.DataValue[0].id = myguid; ?
Thanks in advance,
JanThursday, March 19, 2009 3:16 PM
Answers
-
Lookup fields consist of three parts: name, GUID and entityname. Since this is stored as an array, you have to create an array with these three objects and use the array to set the lookup.
Example:
var lookupItem = new Array(); var lci = new Object(); lci.id = "{ABCDEF-123456-78901}"; lci.name = "Microsoft"; lci.typename = "Account"; lookupItem[0] = lci; crmForm.all.myfield.DataValue = lookupItem; - Proposed as answer by Daniel Middel Thursday, March 19, 2009 3:48 PM
- Marked as answer by Jan Klode Thursday, March 19, 2009 4:45 PM
Thursday, March 19, 2009 3:48 PM
All replies
-
Lookup fields consist of three parts: name, GUID and entityname. Since this is stored as an array, you have to create an array with these three objects and use the array to set the lookup.
Example:
var lookupItem = new Array(); var lci = new Object(); lci.id = "{ABCDEF-123456-78901}"; lci.name = "Microsoft"; lci.typename = "Account"; lookupItem[0] = lci; crmForm.all.myfield.DataValue = lookupItem; - Proposed as answer by Daniel Middel Thursday, March 19, 2009 3:48 PM
- Marked as answer by Jan Klode Thursday, March 19, 2009 4:45 PM
Thursday, March 19, 2009 3:48 PM -
Thanks, thats it!
The form needs to be saved to display the new value of the lookup field. How did you solve this problem?
Regards
Jan
Thursday, March 19, 2009 4:06 PM -
You can force the new value, but this is mostly used whenever you want to change a readonly field and save the change into the database.
crmForm.all.myfield.ForceSubmit = true;
The best way is to run the save event dynamically without having to press the save button:
crmForm.Save(); - Proposed as answer by Daniel Middel Friday, March 20, 2009 8:21 AM
Friday, March 20, 2009 8:21 AM