Using filter with Customer screen in Acumatica API

耗尽温柔 提交于 2019-12-02 04:32:39

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.

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];

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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!