Customer Engagement & Dynamics CRM Forum

Expand all | Collapse all

Can I store null values in reference field?

  • 1.  Can I store null values in reference field?

    Posted Jun 14, 2019 12:03 PM
    Does anyone know how can I resolve this issue or faced a similar problem like this?
    I have a form where I want to use it for giving 2 different reference fields field1, field2.
    Both the field1 and field2 are lookup values
    So when am giving feild1 value I should be able to make the field2 as null value and vice versa when adding a record.
    At least I have to be able to make the field as optional but we can't make the referencing field as optional as of my knowledge.
    Could you please suggest me if you have any idea how to resolve my issue.

    ------------------------------
    [Hema] [Shamala]
    [Software Developer]
    [Ahaapps LLC]
    [Glen Allen] [VA]
    ------------------------------


  • 2.  RE: Can I store null values in reference field?

    Posted Jun 14, 2019 08:59 PM
    Hema, i think i understand what you are looking to accomplish and i think you can handle this through a little JavaScript.

    One option is to write some code on both fields OnChange event.

    This way you could check if field 1 has a new value entered... if so, set field 2 to null.

    And a second method on field 2, so that if it is changed and a value is entered you can null out field one.

    That would look something like this.

    OnChange Event for Field 1

    var lookupfield1value= Xrm.Page.getAttribute(field1);
    if (lookupfield1value!= null)
    {
    Xrm.Page.getAttribute(field2).setValue(null);
    }

    You would similarly reverse for field 2

    Also this is off the top of my head so you will need to adjust and test for your specific use case and scenario, but this should get you started.

    ------------------------------
    Nicholas Cole
    Enterprise Solutions Developer
    SMC3
    Peachtree City GA
    ------------------------------



  • 3.  RE: Can I store null values in reference field?

    Posted 29 days ago
    Are you trying to set it in plugins? If so:
    Entity localName = new Entity("schemaname");
    localName.Id = guidOfRecord;
    localName["fieldToUpdate"] = null;
    crmService.Update(localName);

    ------------------------------
    Nikhil Rajendran
    Aha Apps
    Glen Allen VA
    ------------------------------



  • 4.  RE: Can I store null values in reference field?

    GOLD CONTRIBUTOR
    Posted 29 days ago
    You could possibly create a Business Rule to "clear" the value of one field when the opposite contains data.

    ------------------------------
    Ben Edgren
    CRM Applications Manager
    Hufcor, Inc
    Janesville WI
    ------------------------------



If you've found this thread useful, dive deeper into User Group community content by role