Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » Null reference on GetOrders

Null reference on GetOrders

Keld Gøtterup
Reply

Dynamicweb.Ecommerce.Orders.Order.GetOrders("SELECT * FROM EcomOrders Where OrderCart = 'False' AND OrderStateId not in ('OS9','OS3','OS4') AND OrderTransactionStatus = 'Succeeded'")

Gives a null reference with below stacktrace, the sql works fine when used in SQL server management

System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.Common.Context.GetCurrency()
   at Dynamicweb.Ecommerce.Prices.PriceInfo..ctor()
   at Dynamicweb.Ecommerce.Orders.Order..ctor(IDataReader dataReader)
   at Dynamicweb.Ecommerce.Orders.OrderCollection.Load(String sql)
   at Dynamicweb.Ecommerce.Orders.Order.GetOrderCollection(String query)
   at Dynamicweb.Ecommerce.Orders.Order.GetOrders(String query, Boolean preLoadOrderLines)
   at Pilgrim.Website.CustomModules.Helpers.OrderTransfer.ExportAllOrders()


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Does the query return any results? I ran into this in the past and had to specify false as the second param to the call to GetOrders when the query doesn't return results:

var hasOrders = Order.GetOrders(sql, false).Any();
if (hasOrders)
{
  var orders = Order.GetOrders(sql, true); 
  ... do work here with the orders

}

 

 
Keld Gøtterup
Reply

The query returns results and it worked without issues before upgrading to DW9
 

 
Nicolai Pedersen
Reply
This post has been marked as an answer

In what context (from where and how) do you run this piece of code?

It might be solved with 9.2.8 which is not yet released - it has to do with context where we have changed some behavior.

BR Nicolai

Votes for this answer: 1
 
Keld Gøtterup
Reply

Im trying to run the code in a webservice so i can export the orders to AX

We are already planning to upgrade 9.2.8 due to performance issues aswell

 
Nicolai Pedersen
Reply

ok.

In a webservice, you might not have a session state - that can be the issue. You can make sure the webservice uses IRequireSessionState or by adding [WebMethod(EnableSession=true)]

BR Nicolai

 

You must be logged in to post in the forum