Skip to main content

We are using C# with Swagger definition to access a Web Service Endpoint

We are attempting to perform a filter on the SalesOrderClient GetListAsync and would like to perform a substringof filter on the OrderNbr field to find any orders that contain the value that has been specified.

 

SalesOrderClient soClient = new SalesOrderClient(httpClient);
soClient.BaseUrl = "http://localhost/Acumatica_DEV/entity/Test/20.200.001";

select = "OrderNbr, OrderType, Status, CustomerID, Details/LineNbr, Details/InventoryID, Details/OpenQty";
if (!string.IsNullOrWhiteSpace(e.RequestData.OrderNumber))
    filter = "substringof(OrderNbr.Value, '" + e.RequestData.OrderNumber + "')";
else
    filter = "OrderType eq 'SO' and Status eq 'Open'";

IEnumerable<SalesOrder> salesOrders = await soClient.GetListAsync(select, filter, "details", "", null, null);
foreach (SalesOrder salesOrder in salesOrders)
{
    // Process Results
}

 

When we execute the search the error returned is

Unable to cast object of type 'System.String' to type 'PX.Api.ContractBased.Models.EntitySearchField'.

 

Is there a way to apply the substring, startswith or endswith filters here?

Thanks

Chris

 

Substringof function has the reversed order of parameters. 

The first parameter must be constant value and the second parameter must be a field name.

Example

{{sitename}}/entity/Default/21.200.001/JournalTransaction?$filter=contains(BatchNbr,'GL')

So in your case you need:

  filter = $"substringof('{e.RequestData.OrderNumber}', OrderNbr)";

 

Thank you that fixed it.


Substringof function has the reversed order of parameters. 

The first parameter must be constant value and the second parameter must be a field name.

Example

{{sitename}}/entity/Default/21.200.001/JournalTransaction?$filter=contains(BatchNbr,'GL')

So in your case you need:

  filter = $"substringof('{e.RequestData.OrderNumber}', OrderNbr)";

 


I tried that first and got the same error.


Have you tried replacing

‘substringof(OrderNbr.Value,’

with ‘substringof(OrderNbr,’ ?


Reply