locked
CRM 2011 Update Entity with NULL RRS feed

  • Question

  • I am trying to update a Entity that is an OptionSetValue, the values it will update from are in a radioboxlist and one of the option is blank/null. Is there a way to pass the null value to CRM Entity to update?

    This is the radiobox list:

            <asp:RadioButtonList RepeatDirection="Vertical" Width="250px" CellPadding="0" CellSpacing="0" ID="rblChangeButtonType" runat="server" AutoPostBack="False" SelectedValue='<%# Bind("EvalVal") %>'>
            <asp:ListItem Value="" Text="No Evaluation Yet" />
            <asp:ListItem Value="100000000" Text="A - Pending order or visit" />
            <asp:ListItem Value="100000001" Text="B - 75% probability of a sale in 6 months" />
            <asp:ListItem Value="100000002" Text="C - 50% probability of a sale in 12 months" />
            <asp:ListItem Value="100000004" Text="F - 0% probability of a sale" />
          </asp:RadioButtonList>
    

    And this is the code I am using to update the Entity, it works for all the values but the blank one.

    int colderEval = int.Parse(rblChangeButtonType.SelectedValue.ToString());
    
      OptionSetValue selectedEval = new OptionSetValue(colderEval);
    
      Entity opportunity = new Entity("opportunity") { Id = oppGuid };
      opportunity["new_colderevaluation"] = selectedEval;
    

    Any idea how to pass the blank one also? Thanks!

    Wednesday, August 31, 2011 3:03 AM

Answers

  • if (String.IsNullOrEmpty(rblChangeButtonType.SelectedValue.ToString) == true)

    {

        Entity opportunity = new Entity("opportunity") { Id = oppGuid };

        opportunity["new_colderevaluation"] = null;

    }

    else

    {

    int colderEval = int.Parse(rblChangeButtonType.SelectedValue.ToString());

      OptionSetValue selectedEval = new OptionSetValue(colderEval);

      Entity opportunity = new Entity("opportunity") { Id = oppGuid };
      opportunity["new_colderevaluation"] = selectedEval;

    }


    daemon lin
    • Marked as answer by CrazyeD1583 Wednesday, August 31, 2011 1:54 PM
    Wednesday, August 31, 2011 3:30 AM