2011-08-31 2 views
1

OptionSetValue 인 엔터티를 업데이트하려고하는데 업데이트 할 값이 radioboxlist에 있고 옵션 중 하나가 공백/null입니다. 업데이트 할 CRM 엔티티에 null 값을 전달하는 방법이 있습니까? NULL로 속성 업데이트

는 radiobox의 목록입니다

<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> 

그리고 이것이 내가 엔티티를 업데이트 사용하고있는 코드, 모든 값하지만 빈 하나를 작동합니다.

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

OptionSetValue selectedEval = new OptionSetValue(colderEval); 

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

공백을 전달하는 방법에 대한 아이디어가 있으십니까?

+0

처럼, 법인 또는에서 attributeCollection 중 하나에 대한 확장자 방법으로 이러한 변경 될 수 있습니다 .. – Chaos

답변

2

그냥 null로 당신의 특별한 빈 값을 확인하고 필드를 설정 : 내가 추가 한

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

if (rblChangeButtonType.SelectedValue.ToString() != string.Empty) 
{ 
    int colderEval = int.Parse(rblChangeButtonType.SelectedValue.ToString()); 
    OptionSetValue selectedEval = new OptionSetValue(colderEval); 

    opportunity["new_colderevaluation"] = selectedEval; 
} 
else 
{ 
    opportunity["new_colderevaluation"] = null; 
} 
1

당신과 같이, null로 속성을 설정할 수 있습니다 필요한 경우

Entity opportunity = new Entity("opportunity") { Id = oppGuid }; 
opportunity["new_colderevaluation"] = null; 
-1

몇 가지 간단한 메서드를 내 CrmUtil 정적 클래스 꽤 많이 사용합니다. 이것들이 도움이 될 수 있습니다. 난 당신이 그때 "아직 평가"에 대한 옵션을 추가 할 수 있다면

public static class CrmUtils 
{ 
    public static OptionSetValue OptionSetValueOrNull(int? value) 
    { 
     return value == null ? null : new OptionSetValue(value); 
    } 

    public static EntityReference EntityReferenceOrNull(Guid? id, string entityName) 
    { 
     return id == null ? null : new EntityReference(entityName, id); 
    } 
} 

양자 택일로, 당신은 너무

entity.SetEntityReference(nullableId, "account"); 
entity.Attributes.SetEntityReference(nullableId, "account"); 
관련 문제