2017-02-13 3 views
0

アドレスレコードを作成しようとしていますが、エラーが発生し続けます。MS CRM:アドレスレコードを作成すると無効な属性値型エラーが発生する

public const int OBJECT_TYPE_CONTACT = 2; 



int addressTypeCode = 3; //Primary Address 
if (i == 2) addressTypeCode = 1; //Billing Address 
if (i == 3) addressTypeCode = 2; //Shipping Address 

Entity newAddress = new Entity("customeraddress"); 
newAddress.Attributes["parentid"] = new EntityReference("contact", existingContact.Id); 
newAddress.Attributes["addresstypecode"] = addressTypeCode; 
newAddress.Attributes["objecttypecode"] = OBJECT_TYPE_CONTACT; 
newAddress.Attributes["line1"] = "temp1"; 
newAddress.Attributes["line2"] = "temp2"; 
newAddress.Attributes["line3"] = "temp3"; 
newAddress.Attributes["city"] = "temp3"; 
newAddress.Attributes["stateorprovince"] = "temp3"; 
newAddress.Attributes["postalcode"] = "temp3"; 
newAddress.Attributes["country"] = "temp3"; 

Guid id = service.Create(newAddress); 

エラーがobjecttypecodeを設定する行にスローを次のように

The application terminated with an error. 
Code: -2147220989 
Message: Incorrect attribute value type System.Int32 

コードです。私はエラーコードが "無効な引数"を意味することを知っています。解決策2では連絡先を参照するので、問題の内容はわかりません。

+0

エラーは、実際には 'Guid id = service.Create(newAddress);'という行を投げています。 'Entity'クラスは型の認識を持たないので、そのエラーは' Entity.Attributes'コレクションの項目を追加/変更することは決してありません。 'CrmSvcUtil.exe'の初期バインドタイプを使用すると、警告をタイプすることができます。 – Nicknow

答えて

1

あなたは、この行を変更する必要があります。

newAddress.Attributes["addresstypecode"] = addressTypeCode;

へ:

newAddress.Attributes["addresstypecode"] = new OptionSetValue(addressTypeCode);

それはオプションでは、タイプがOptionSetValue、ないintでなければならない設定なので。

+0

ありがとう、私はその1つを見たはずです –

関連する問題