Skip to main content
Solved

Filtering Sales Order with substringof on OrderNbr field

  • January 10, 2022
  • 4 replies
  • 431 views

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

 

Best answer by Dmitrii Naumov

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)";

 

4 replies

  • Author
  • Freshman II
  • 8 replies
  • January 10, 2022

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.


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • 771 replies
  • Answer
  • January 10, 2022

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)";

 


  • Author
  • Freshman II
  • 8 replies
  • January 10, 2022

I tried that first and got the same error.


Kyle Vanderstoep
Varsity I
Forum|alt.badge.img+1

Have you tried replacing

‘substringof(OrderNbr.Value,’

with ‘substringof(OrderNbr,’ ?