Acumatica客户通过API邮寄设置

时间:2017-03-29 06:18:23

标签: c# acumatica

我正在尝试通过Screen API创建客户邮件设置。但是,我没有成功保存数据。

这是我的代码:

public static class CustomerManager
{
    private static Value CreateValue(
        string value,
        Command linkedCommand)
    {
        return new Value()
        {
            Value = value,
            LinkedCommand = linkedCommand
        };
    }

    private static Value CreateValueCommit(
        string value,
        Command linkedCommand)
    {
        return new Value()
        {
            Value = value,
            LinkedCommand = linkedCommand,
            Commit = true
        };
    }

    public static void ManageContact() {
        try {
            using (var context = WebServiceConnector.InitializeScreenWebService()) {
                var customerSchema = context.AR303000GetSchema();

                var commands = new List<Command>() {
                    CreateValueCommit("C00001", customerSchema.CustomerSummary.CustomerID),
                    CreateValueCommit("INVOICE", customerSchema.MailingSettingsMailings.MailingID),
                    CreateValue("mail@mail.com", customerSchema.MailingSettingsMailings.EmailAccountEmailAddress),
                    CreateValueCommit("InvoiceNotification", customerSchema.MailingSettingsMailings.NotificationTemplate),
                    customerSchema.MailingSettingsRecipients.ServiceCommands.NewRow,
                    CreateValueCommit("Contact", customerSchema.MailingSettingsRecipients.ContactType),
                    CreateValueCommit("Doe John, Dr.", customerSchema.MailingSettingsRecipients.ContactID),
                    customerSchema.Actions.Save,
                    customerSchema.CustomerSummary.CustomerID,
                    customerSchema.MailingSettingsMailings.EmailAccountEmailAddress,
                    customerSchema.MailingSettingsRecipients.ContactID
                };

                var customer = context.AR303000Submit(commands.ToArray());

                context.Logout();
            }
        }
        catch (Exception ex) {

            throw ex;
        }
    }
}

正确保存的唯一值是通知模板。

调试后,我检查了Mailing Recipient,值在我的客户退货对象中。但是客户屏幕上没有任何内容:

documentation

1 个答案:

答案 0 :(得分:0)

“邮件设置”选项卡自动化思科Web服务并不容易,原因如下:

  • 初始邮件设置在Customer Class级别定义。允许用户修改初始设置或创建新的特定于分支的设置。只能为每个MailingID / Branch对定义一个邮件设置

  • “收件人”网格仅显示为当前邮件设置定义的收件人

  • 电子邮件帐户列的
  • DisplayMode 设置为 文字 ,需要将最初生成的FieldName从EMailAccountID更改为{ {1}}。否则,API将忽略为此列定义的值:

    EMailAccountID!Address

    Aspx中邮件网格的定义:

    Content customerSchema = context.GetSchema();
    customerSchema.MailingSettingsMailings.EmailAccount.FieldName += "!Address";
    

以下是3个样本,展示了如何通过基于屏幕的API使用“邮件设置”选项卡:

  1. 为客户类级别定义的初始邮件设置插入新收件人:

    <px:PXGrid ID="gridNS" runat="server" SkinID="DetailsInTab" Caption="Mailings" ... >
        ...
        <Levels>
            <px:PXGridLevel DataMember="NotificationSources" DataKeyNames="SourceID,SetupID">
                <RowTemplate>
                    ...
                </RowTemplate>
                <Columns>
                    ...
                    <px:PXGridColumn DataField="EMailAccountID" DisplayMode="Text" Width="200px" />
                    ...
                </Columns>
                ...
            </px:PXGridLevel>
        </Levels>
    </px:PXGrid>
    
  2. 更新在Customer Class级别邮件设置中定义的初始邮件设置,并为其添加新收件人:

    Screen context = new Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Url = "http://localhost/StackOverflow/Soap/AR303000.asmx";
    context.Login(username, password);
    
    try
    {
        Content customerSchema = context.GetSchema();
        var commands = new Command[]
        {
            new Value
            {
                Value = "ABCSTUDIOS",
                LinkedCommand = customerSchema.CustomerSummary.CustomerID
            },
    
            new Key
            {
                Value = "='INVOICE'",
                FieldName = customerSchema.MailingSettingsMailings.MailingID.FieldName,
                ObjectName = customerSchema.MailingSettingsMailings.MailingID.ObjectName
            },
            customerSchema.MailingSettingsMailings.MailingID,
    
            customerSchema.MailingSettingsRecipients.ServiceCommands.NewRow,
            new Value
            {
                Value = "Contact",
                LinkedCommand = customerSchema.MailingSettingsRecipients.ContactType,
            },
            new Value
            {
                Value = "Harper, Travis",
                LinkedCommand = customerSchema.MailingSettingsRecipients.ContactID,
                Commit = true
            },
            customerSchema.Actions.Save
        };
        context.Submit(commands);
    }
    finally
    {
        context.Logout();
    }
    
  3. 要创建新的特定于分支的邮件设置并为其添加新收件人:

    Screen context = new Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Url = "http://localhost/StackOverflow/Soap/AR303000.asmx";
    context.Login(username, password);
    
    try
    {
        Content customerSchema = context.GetSchema();
        customerSchema.MailingSettingsMailings.EmailAccount.FieldName += "!Address";
    
        var commands = new Command[]
        {
            new Value
            {
                Value = "ACTIVESTAF",
                LinkedCommand = customerSchema.CustomerSummary.CustomerID
            },
    
            new Key
            {
                Value = "='INVOICE'",
                FieldName = customerSchema.MailingSettingsMailings.MailingID.FieldName,
                ObjectName = customerSchema.MailingSettingsMailings.MailingID.ObjectName
            },
            new Value
            {
                Value = "admin@revisiontwo.com",
                LinkedCommand = customerSchema.MailingSettingsMailings.EmailAccount,
                Commit = true
            },
    
            customerSchema.MailingSettingsRecipients.ServiceCommands.NewRow,
            new Value
            {
                Value = "Contact",
                LinkedCommand = customerSchema.MailingSettingsRecipients.ContactType,
            },
            new Value
            {
                Value = "Dunnaville, Linda",
                LinkedCommand = customerSchema.MailingSettingsRecipients.ContactID,
                Commit = true
            },
            customerSchema.Actions.Save
        };
        context.Submit(commands);
    }
    finally
    {
        context.Logout();
    }