在Acumatica API中对客户屏幕使用过滤器 [英] Using filter with Customer screen in Acumatica API

查看:34
本文介绍了在Acumatica API中对客户屏幕使用过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过查看Acumatica的API示例,我编写了代码以基于单个过滤器从客户屏幕导出一些数据。过滤器应强制要求客户的电子邮件地址等于特定值(一旦生效,我还将使用加密的密码检查自定义字段)。但是由于某种原因,导出功能返回的似乎是我们数据库中每个客户的记录。谁能说出我的过滤器或其他原因在做什么?调试器的代码和屏幕截图如下。

Looking at the API examples from Acumatica, I have written code to Export some data from the Customer screen based on a single filter. The filter should enforce that the Customer's email address equals a particular value (once that's working, I will also check a custom field with an encrypted password). Yet for some reason the Export function is returning what appears to be every customer record in our database. Can anyone tell what I am doing wrong with my filter, or anything else? Code and screenshot from debugger are below.

谢谢!

Public Function ValidateUser(ByVal emailAddress As String, ByVal password As String, ByRef customerFirstName As String, ByRef customerLastName As String, ByRef customerCountry As String, ByRef customerPhone As String, ByRef customerCell As String) As String

    Dim customer As AR303000Content = m_context.AR303000GetSchema()
    m_context.AR303000Clear()

    Dim emailFilter As Filter = New Filter()
    emailFilter.Field = customer.GeneralInfoMainContact.Email
    emailFilter.Condition = FilterCondition.Equals
    emailFilter.Value = emailAddress

    Dim searchfilters() As Filter = {emailFilter}
    Dim searchCommands() As Command = {customer.CustomerSummary.CustomerID, customer.CustomerSummary.CustomerName, customer.GeneralInfoMainContact.Phone1, customer.GeneralInfoMainContact.Phone2, customer.GeneralInfoMainAddress.Country}
    Dim searchResult As String()() = m_context.AR303000Export(searchCommands, searchfilters, 0, False, False)

    Dim numRecords = searchResult.Length
    Dim customerID As String = ""
    Dim customerName As String = ""
    If numRecords > 0 Then
        ' we found a user with that email address
        Dim i As Integer = 0
        For i = 1 To numRecords
            customerID = searchResult(i - 1)(0)
            customerName = searchResult(i - 1)(1)
            customerPhone = searchResult(i - 1)(2)
            customerCell = searchResult(i - 1)(3)
            customerCountry = searchResult(i - 1)(4)
        Next
    End If

    Dim spaceInName = customerName.IndexOf(" ")
    If spaceInName >= 0 Then
        customerFirstName = customerName.Substring(0, spaceInName)
        customerLastName = customerName.Substring(spaceInName + 1)
    End If

    Return customerID
End Function

推荐答案

过滤器通常仅适用于主视图(例如,主表-在这个ca se BAccount + Customer)。如果您尝试过滤包含在辅助视图中的数据,系统将静默忽略它。电子邮件地址和联系人记录数据包含在联系人表中,因此您不能按这些字段进行过滤。

Filters generally only work on the primary view (e.g., main table - in this case BAccount+Customer). If you try to filter on data contained in secondary views, the system will silently ignore it. The e-mail address and contact record data is contained in the Contact table, and therefore you cannot filter by these fields.

我认为这种行为应该得到改善,并且我如果您尝试过滤不允许的内容,则会在内部提出建议,至少会引发异常。

I think this behaviour should be improved, and i'll file a suggestion internally to at least throw an exception if you try to filter on something that's not allowed. It will at least make troubleshooting this problem easier.

作为替代方案,如果您使用Submit()函数加载特定记录,则可以更改基础FieldName在架构中使其基于另一个字段进行匹配。下面的示例显示了如何通过基于电子邮件地址查找客户来更新客户信用验证设置:

As an alternative, if you're using Submit() function to load a specific record, you can alter the underlying FieldName in the schema to have it match based on another field. This example below shows how to update a customer credit verification settings by looking up customer based on e-mail address:

Screen context = new Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.Url = Url;
context.Login(Login, Password);

AR303000Content custSchema = context.AR303000GetSchema();

custSchema.CustomerSummary.CustomerID.FieldName += 
    ("!" + custSchema.CustomerSummary.ServiceCommands.FilterEmail.FieldName);

var commands = new Command[]
{
    new Value 
    {
        Value = "demo@gmail.com", 
        LinkedCommand = custSchema.CustomerSummary.CustomerID 
    },

    new Value 
    {
        Value = "Disabled", 
        LinkedCommand = custSchema.GeneralInfoCreditVerificationRulesCreditVerification.CreditVerification 
    },

    custSchema.Actions.Save,

    custSchema.GeneralInfoFinancialSettings.CustomerClass
};
var customer = context.AR303000Submit(commands)[0];

还可以使用Submit()函数检索数据。通常,您将需要的字段放在命令数组中,但是如果您特别需要CustomerID,则需要使用技巧来检索它,因为CustomerID.FieldName值已更改为添加电子邮件过滤器。示例如下:

You can also use the Submit() function to retrieve data. Usually you place the fields you need in the commands array, but if you specifically need the CustomerID you'll need to use a trick to retrieve it since the CustomerID.FieldName value was altered to add the e-mail filter. Here's the sample:

private static string GetCustomerIDByEmail(string eMailAddress)
{
    Screen context = new Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Login("admin", "admin");

    Content custSchema = context.GetSchema();

    custSchema.CustomerSummary.CustomerID.FieldName +=
        ("!" + custSchema.CustomerSummary.ServiceCommands.FilterEmail.FieldName);

    var commands = new Command[]
    {
        new Value 
        {
            Value = eMailAddress,
            LinkedCommand = custSchema.CustomerSummary.CustomerID
        },

        // Manually define the Field by setting ObjectName and FieldName. We can't use custSchema.CustomerSummary.CustomerID field because it was altered to make it search by e-mail.
        new Field
        {
            ObjectName = "BAccount",
            FieldName = "AcctCD"
        }
    };

    var results = context.Submit(commands);

    if (results.Length == 0)
        return "Not found";
    else
        return results[0].CustomerSummary.CustomerID.Value;
}

这篇关于在Acumatica API中对客户屏幕使用过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆