如何使用 Web 服务使用过滤器导出库存项目以进行搜索

How to export Stock Items with filters for search using Web Services

我发送的 SOAP 消息是这个:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.acumatica.com/typed/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Body>
        <ns1:Export>
            <ns1:commands>
                <ns1:Command xsi:type="ns1:Field">
                    <ns1:FieldName>InventoryCD</ns1:FieldName>
                    <ns1:ObjectName>Item</ns1:ObjectName>
                    <ns1:Value>InventoryID</ns1:Value>
                    <ns1:Commit>true</ns1:Commit>
                    <ns1:LinkedCommand xsi:type="ns1:Action">
                        <ns1:FieldName>Cancel</ns1:FieldName>
                        <ns1:ObjectName>Item</ns1:ObjectName>
                        <ns1:LinkedCommand xsi:type="ns1:Key">
                            <ns1:FieldName>InventoryCD</ns1:FieldName>
                            <ns1:ObjectName>Item</ns1:ObjectName>
                            <ns1:Value>=[Item.InventoryCD]</ns1:Value>
                        </ns1:LinkedCommand>
                    </ns1:LinkedCommand>
                </ns1:Command>
                <ns1:Command xsi:type="ns1:Field">
                    <ns1:FieldName>Descr</ns1:FieldName>
                    <ns1:ObjectName>Item</ns1:ObjectName>
                    <ns1:Value>Description</ns1:Value>
                </ns1:Command>
            </ns1:commands>
            <ns1:filters>
                <ns1:Filter>
                    <ns1:Field>
                        <ns1:FieldName>Descr</ns1:FieldName>
                        <ns1:ObjectName>Item</ns1:ObjectName>
                    </ns1:Field>
                    <ns1:Condition>Contain</ns1:Condition>
                    <ns1:Value>TEST</ns1:Value>
                    <ns1:OpenBrackets>0</ns1:OpenBrackets>
                    <ns1:CloseBrackets>0</ns1:CloseBrackets>
                    <ns1:Operator>And</ns1:Operator>
                </ns1:Filter>
            </ns1:filters>
            <ns1:topCount>5</ns1:topCount>
            <ns1:includeHeaders>false</ns1:includeHeaders>
            <ns1:breakOnError>false</ns1:breakOnError>
        </ns1:Export>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我用来发送此消息的 PHP 代码是这个:

<?php

$context = new Screen("<URL>", array('trace' => TRUE));
$login = new Login();
$login->name = "<LOGINUSER>";
$login->password = "<LOGINPASS>";
$context->Login($login);

$IN202500 = $context->GetSchema(new GetSchema());
$clear = $context->Clear(new Clear());
$IN202500content = $IN202500->GetSchemaResult;

$field = new Field();
$field->FieldName = $IN202500content->StockItemSummary->Description->FieldName;
$field->ObjectName = $IN202500content->StockItemSummary->Description->ObjectName;

$filter = new Filter();
$filter->Field = $field;
$filter->Condition = FilterCondition::Contain;
$filter->Value = "TEST";
$filter->Operator = FilterOperator::_And;
$filter->OpenBrackets = 0;
$filter->CloseBrackets = 0;

$export = new Export();
$export->commands = array(
    $IN202500content->StockItemSummary->InventoryID,
    $IN202500content->StockItemSummary->Description
);
$export->topCount = 5;
$export->includeHeaders = false;
$export->breakOnError = false;
$export->filters = array(
    $filter
);

$export_result = $context->Export($export);

?>

我收到的响应与未设置过滤器时的结果相同。如何筛选描述子字符串的结果?

            DateTime syncDate = new DateTime(2013,1,1);
        context.IN202500Clear();            
        result = context.IN202500Export(
            new Command[]
            {                    
                IN202500.StockItemSummary.ServiceCommands.EveryInventoryID,
                IN202500.StockItemSummary.InventoryID,
                IN202500.StockItemSummary.Description,
                IN202500.WarehouseDetails.WarehouseWarehouseID,
                IN202500.WarehouseDetails.QtyOnHand
            },
            new Filter[]
            {                    
                new Filter { Field = new Field { ObjectName = IN202500.StockItemSummary.ItemStatus.ObjectName, FieldName = IN202500.StockItemSummary.ItemStatus.FieldName }, Condition = FilterCondition.Equals, Value = "Active", Operator = FilterOperator.And },
                new Filter { Field = new Field { ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName, FieldName = "LastModifiedDateTime" }, Condition = FilterCondition.GreaterOrEqual, Value = syncDate.ToLongDateString(), Operator = FilterOperator.And },                    
            },
            0,false,false
        );
        //results
        foreach (string[] item in result)
        {
            Console.WriteLine(
                item[0] + ";" + 
                item[1] + ";" + 
                item[2] + ";" + 
                item[3] + ";"
            );
        }

问题在于过滤器,它最后是如何发送的。

正在发送的是:

<ns1:Value>TEST</ns1:Value>

相反,需要指定类型和命名空间:

<ns1:Value xsi:type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema">TEST</ns1:Value>

否则,Acumatica 将不会检测过滤器的值。

我发现过滤器在默认屏幕上不能正常工作,它们只适用于 id 字段。如果您创建一个通用查询,您可以指定更多过滤器并将结果集缩小到您需要的字段。此外,一般查询屏幕通常 运行 比标准默认屏幕快。