在Dynamics CRM插件中使用C#创建PDF的步骤是什么

时间:2014-04-18 05:06:30

标签: c# docusignapi dynamics-crm-online

我已阅读有关3.0 API的所有文档。请不要再把我送到那里。我可以使用自定义字段在DocuSign上创建模板并将其发送到信封中,但似乎无法用我的应用程序中的值填充自定义字段(标签?)。谁能告诉我确切的方法? IE:我尝试过身份验证 - > CreateEnvelopeFromTemplates - > SendEnvelope,只获取空表单字段。我尝试过身份验证 - > CreateEnvelope-> SendEnvelope ....空字段。无论如何,我无法在本地文件系统上托管该文件,所以我认为即使它确实有效,这将是一个死胡同(CRM Online)。 这是模板的样子: !https://dl.dropboxusercontent.com/u/24627933/DocuSign.PNG 这是我认为最有希望的例子:

string auth = "<DocuSignCredentials><Username>" + _userName
     + "</Username><Password>" + _password
     + "</Password><IntegratorKey>" + _IntegratorKey
     + "</IntegratorKey></DocuSignCredentials>";

APIServiceSoapClient _apiClient = new APIServiceSoapClient("APIServiceSoap", _apiUrl);

/* tried this too
Tab RoutingNumber = new Tab()
{
    Name = "RoutingNumber",
    Type = TabTypeCode.Custom,
    Bold = true,
    Value = "1234 555 765"
};
Tab PayeeName = new Tab()
{
    Name = "PayeeName",
    Value = "PaiYee Na Me",
    Bold = false,
    Type = TabTypeCode.Custom
};
  */

// Construct all the recipient information
Recipient[] recipients = CreateOneSigner();
TemplateReferenceRoleAssignment[] finalRoleAssignments = new TemplateReferenceRoleAssignment[1];
finalRoleAssignments[0] = new TemplateReferenceRoleAssignment();
finalRoleAssignments[0].RoleName = recipients[0].RoleName;
finalRoleAssignments[0].RecipientID = recipients[0].ID;

// Use a server-side template -- you could make more than one of these
TemplateReference templateReference = new TemplateReference();
templateReference.TemplateLocation = TemplateLocationCode.Server;
templateReference.Template = "B3DAD8FD-1B48-4C62-9DB6-A48E5C5B40DC";
//templateReference.Template = "ABE98BE7-A400-493B-A3A3-BA489CEEA166"; 
templateReference.RoleAssignments = finalRoleAssignments;
templateReference.AdditionalTabs = new Tab[] { RoutingNumber, PayeeName };

// Construct the envelope information
EnvelopeInformation envelopeInfo = new EnvelopeInformation();
envelopeInfo.AccountId = _accountId;
envelopeInfo.Subject = "Irrevocable Commission Test";
envelopeInfo.EmailBlurb = "This is the Irrevocable Commission Disbursement Authorization form related to your Advance Pay request.";



CustomField Company = new CustomField()
{
    Name = "Company",
    Value = "Some company.",
    CustomFieldTypeSpecified = true,
    CustomFieldType = CustomFieldType.Text,
    Show = "Yes",
    Required = "Yes"
};
CustomField PayeeName = new CustomField()
{
    Name = "PayeeName",
    Value = "some name",
    CustomFieldTypeSpecified = true,
    CustomFieldType = CustomFieldType.Text,
    Show = "Yes",
    Required = "Yes"
};
CustomField RoutingNumber = new CustomField()
{
    Name = "RoutingNumber",
    Value = "my routing num",
    CustomFieldTypeSpecified = true,
    CustomFieldType = CustomFieldType.Text,
    Show = "Yes",
    Required = "Yes"
};
CustomField SendToName = new CustomField()
{
    Name = "SendToName",
    Value = "Residential Advance",
    CustomFieldTypeSpecified = true,
    CustomFieldType = CustomFieldType.Text,
    Show = "Yes",
    Required = "Yes"
};
CustomField AccountNumber = new CustomField()
{
    Name = "AccountNumber",
    Value = "my account ",
    CustomFieldTypeSpecified = true,
    CustomFieldType = CustomFieldType.Text,
    Show = "Yes",
    Required = "Yes"
};
CustomField AgentName = new CustomField()
{
    Name = "AccountNumber",
    Value = "my agent ",
    CustomFieldTypeSpecified = true,
    CustomFieldType = CustomFieldType.Text,
    Show = "Yes",
    Required = "Yes"
};
envelopeInfo.CustomFields = new CustomField[] { 
    Company, PayeeName, RoutingNumber, AccountNumber, SendToName
};

recipients[0].CustomFields = new CustomField[] {
    Company, PayeeName, RoutingNumber, AccountNumber, SendToName
};

using (var scope = new System.ServiceModel.OperationContextScope(_apiClient.InnerChannel))
{
    var httpRequestProperty = new System.ServiceModel.Channels.HttpRequestMessageProperty();
    httpRequestProperty.Headers.Add("X-DocuSign-Authentication", auth);
    System.ServiceModel.OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] =
        httpRequestProperty;

    EnvelopeStatus status1 =
        _apiClient.CreateEnvelopeFromTemplates(new TemplateReference[] { templateReference },
                                                recipients,
                                                envelopeInfo,
                                                false);

    Console.WriteLine(status1);

    if (status1.Status.ToString() == "Created")
    {
        EnvelopeStatus sendStatus = _apiClient.SendEnvelope(status1.EnvelopeID, _accountId);
    }
}

2 个答案:

答案 0 :(得分:0)

我认为您需要使用tabLabel属性来填充数据字段。尝试使用这样的东西:

CustomField AccountNumber = new CustomField()
    {
        TabLabel = "AccountNumber",
        Name = "AccountNumber",
        Value = "my account ",
        CustomFieldTypeSpecified = true,
        CustomFieldType = CustomFieldType.Text,
        Show = "Yes",
        Required = "Yes"
    };

答案 1 :(得分:0)

似乎C#示例中使用的以及上面建议的对象不正确。现在,当我使用TemplateReferenceFieldDataDataValue并将其添加为FieldData.DataValues时,将显示这些值。

        templateReference.RoleAssignments = finalRoleAssignments;
        var dataFieldValues = new TemplateReferenceFieldDataDataValue[3];
        dataFieldValues[0] = new TemplateReferenceFieldDataDataValue();
        dataFieldValues[0].TabLabel = "RoutingNumber";
        dataFieldValues[0].Value = "R12345678";
        dataFieldValues[1] = new TemplateReferenceFieldDataDataValue();
        dataFieldValues[1].TabLabel = "AccountNumber";
        dataFieldValues[1].Value = "A87654321";
        dataFieldValues[2] = new TemplateReferenceFieldDataDataValue();
        dataFieldValues[2].TabLabel = "Escrow";
        dataFieldValues[2].Value = "E777333";

        templateReference.FieldData = new TemplateReferenceFieldData();
        templateReference.FieldData.DataValues = dataFieldValues;

希望能节省一些时间。