无法使用Dynamics CRM

时间:2016-08-16 13:09:00

标签: soap dynamics-crm

您好我正在尝试使用SDK SOAP在Dynamics CRM中创建电子邮件模板记录.Below是我的代码

    var email_body = "ehhlo";
        var email_subject = $("#subject").val();
        var email_title = $("#title").val();

        var templateColumns = {
            "title": Sdk.String,
            "subject": Sdk.String,
            "languagecode": Sdk.Int,
            "templatetypecode": Sdk.OptionSet,
            "body": Sdk.String
        };

        var email = new Sdk.Entity("template");



        initializeEntity(email, templateColumns);

        email.setValue("title", email_title);
        email.setValue("subject", email_subject);
        email.setValue("languagecode", 1033);
        email.setValue("templatetypecode", 1);
        email.setValue("body", email_body);




        try {
            templateid= Sdk.Sync.create(email);
            alert("Created account with id: " + templateid);
        }
        catch (e) {
            throw new Error("Error on Create : " + e.message);
        }

我尝试使用同步和异步两者创建,但我收到了错误

发生意外错误。

使用Fiddler捕获日志时,我收到以下响应

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring xml:lang="en-US">An unexpected error occurred.</faultstring>
<detail><OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
<Message>An unexpected error occurred.</Message>
<Timestamp>2016-08-16T13:01:27.627155Z</Timestamp>
<InnerFault>
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
<Message>System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #9F27DAAC</Message>
<Timestamp>2016-08-16T13:01:27.6427801Z</Timestamp>
<InnerFault i:nil="true"/>
<TraceText i:nil="true"/>
</InnerFault>
<TraceText i:nil="true"/>
</OrganizationServiceFault>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>

现在可以请一些人指出我做错了什么以及为什么 System.InvalidCastException 正在生成。

由于

1 个答案:

答案 0 :(得分:0)

templatetypecode的演员表错误,这不是OptionSet你应该在这里传递实体名称(所以你要传递“帐号”而不是1)。