locked
Null a Lookup value through Javascript RRS feed

  • 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
    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
    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,
    Mike

     

    Thursday, 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.
    Thursday, June 2, 2011 2:11 PM
  • I am using the case sensitive Schema Name for the attribute.

    As I wrote in my previous post, you must use the Logical (all lower case) attribute name when referencing attributes and controls via the Xrm.Page API.
    --pogo (pat) @ pogo69.wordpress.com
    Thursday, 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