Answered by:
Null a Lookup value through Javascript

Question
-
I have a scenario where changing one field should NULL out 3 other Lookup fields. I am hoping to handle this action of setting the fields to NULL through JavaScript using an OnChange event. I have all of the javascript all set for the on change and using alerts I am happy with the logic, I have yet to find out how to NULL a lookup field.
Is there a way to do this through Javascript?
Thanks!
Thursday, June 2, 2011 2:45 AM
Answers
-
CRM 2011:
Xrm.Page.data.entity.attributes.get("logicalattributename").setValue(null);
CRM 4:
crmForm.all.<logicalattributename>.DataValue = null;
Use null to null any attribute value.
--pogo (pat) @ pogo69.wordpress.com- Proposed as answer by Andrii ButenkoMVP, Moderator Thursday, June 2, 2011 6:06 AM
- Unproposed as answer by bruxite Thursday, June 2, 2011 1:08 PM
- Marked as answer by bruxite Friday, June 3, 2011 12:30 AM
Thursday, June 2, 2011 5:23 AM
All replies
-
CRM 2011:
Xrm.Page.data.entity.attributes.get("logicalattributename").setValue(null);
CRM 4:
crmForm.all.<logicalattributename>.DataValue = null;
Use null to null any attribute value.
--pogo (pat) @ pogo69.wordpress.com- Proposed as answer by Andrii ButenkoMVP, Moderator Thursday, June 2, 2011 6:06 AM
- Unproposed as answer by bruxite Thursday, June 2, 2011 1:08 PM
- Marked as answer by bruxite Friday, June 3, 2011 12:30 AM
Thursday, June 2, 2011 5:23 AM -
Pogo,
I have tried what you have suggested and I keep getting errors. I am receiving the error "Unable to get value of the property 'setValue': object is null or undefined". I have tried using this with both a lookup value and a regular text value.
I am using the case sensitive Schema Name for the attribute.
Has anyone been able to get this to work? Being able to null out a field through javascript.
Thanks,
MikeThursday, June 2, 2011 1:08 PM -
I've had the following work for me when needing to reset a Lookup field:
Xrm.Page.getAttribute(lookupFieldName).setValue(
null
);
Kind Regards, Paul.- Proposed as answer by Julio Luque Cuba Thursday, June 2, 2011 2:38 PM
Thursday, June 2, 2011 2:11 PM -
I am using the case sensitive Schema Name for the attribute.
--pogo (pat) @ pogo69.wordpress.comThursday, June 2, 2011 7:32 PM -
For whatever reason it only worked for me when I used the all lowercase name of the field.
Anyway, thanks for the help!
Friday, June 3, 2011 12:30 AM