Developer forum

Forum » Integration » Order state when updating Orders with Data Integration activity

Order state when updating Orders with Data Integration activity

Søren Jakobsen
Reply

Hi Community,

we're updating orders with track&trace and invoice numbers with a Data Integration activity (XML & order provider). We update the orderstate based on the input - moving orders to either state "Shipped" or "Invoiced. Both orderstate "shipped" and "invoiced" are configured to send an email notification to the user. This works fine when changing state manually in DW backend but when this is done through Data integration or Batch integration no mails are send.

Attached import ex. updates order to stateid OS13 (shipped) but this doesn't trigger mail sending. How do I trigger this? do I need to create a scheduled task to loop through orders and change state and save orders subsequently with something like:

order.StateId = state;

Dynamicweb.Ecommerce.Services.Orders.Save(order);?

or?

It's DW 9.13.3

Best regards Søren

2022-03-28_15_40_25-Dynamicweb_Admin_(9.13.3).png order.PNG

Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Soren,
the emails notification is not sent since there are differences of saving the order using the Dynamicweb Data Integration jobs and when it is saved during backend order editing,
the problem is that the Data integration approach is not using the Dynamicweb order saving api and updates orders using sql, so you need to call the api yourself.
You can use the DataIntegration extresibility points to implement the functionality you need.
First implement the TableScript and cache the orders that were/need to be updated. Then in the 
DataIntegration JobFinished notification subscriber for each of the cached order run the code that will send the notification by forcing the state to be changed:
string currentState = order.StateId;
order.StateId = "someNewOrderStateId"; //trigger order state changed flow
order.StateId = currentState; //restore the correct state if needed
order.Save(); //this should fire the email notifications
BR, Dmitrij

 
Søren Jakobsen
Reply

Thanks Dmitriy,

I ended up doing a scheduled task. Orderstate will get changed during execution and order.save() will trigger mail sending but mails are not sesnd due to an exception:

Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object. at Dynamicweb.Ecommerce.Frontend.Renderer.RenderProduct(Product product, Boolean extendedProperties, Template template, Int32 loopCounter, Boolean renderRelated, String productUrl, Int32 quantity, Int32 wishListId, Boolean renderPublicList, Boolean isRecursiveCall, Lazy`1 categoryFieldSorting, Int32 orderLineOfProductCount, RenderingContext renderingContext, String unitId) at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrderLine(OrderLine orderLine, Template template, RenderingContext renderingContext) at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrderLines(OrderLineCollection orderLines, Template parentTemplate, String loopName, RenderingContext renderingContext) at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrderDetails(Template template, Order order, Boolean extendedProperties, OrderTemplateExtenderContext orderContext) at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrder(Order order, Template template, Boolean extendedProperties, Int32 stepNumber, OrderTemplateExtenderContext orderContext) at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrder(Order order, Template template, Boolean extendedProperties, OrderTemplateExtenderContext orderContext) at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrder(Order order, Template template) at Dynamicweb.Ecommerce.Orders.OrderService.SendEmail(Order order, PageView& pageView, String subject, IEnumerable`1 toMailAddresses, String fromMailAddress, String fromMailName, Template& mailTemplate) at Dynamicweb.Ecommerce.Orders.OrderService.SendEmail(Order order, PageView& pageView, String subject, String toMailAddress, String fromMailAddress, String fromMailName, Template& mailTemplate) at Dynamicweb.Ecommerce.Orders.OrderService.SendStateChangedEmail(Order order, OrderState state, PageView pageView) at Dynamicweb.Ecommerce.Orders.OrderService.NotifyOrderStateChanged(Order order) at Dynamicweb.Ecommerce.Orders.OrderService.Save(Order order, Boolean saveOldVersion) at Dynamicweb.Ecommerce.Orders.OrderService.Save(Order order) at PlusPlus.Core.ScheduledTasks.SetOrderStateShipped.Run()

Any ideas? it's a DW 9.13.3

Best regards Søren

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Soren,
it looks like there could be a problem of missing Dynamicweb.Context.Session at the scheduled task running which tries to RenderProduct that require some information from the Dynamicweb.Context.

How are you running the task? Is it manual? If yes, then Dynamicweb.Context.Session is not availble there, could you try to run the task from the
scheduler(automatically) and check if the same error is occured? It seems the Dynamicweb.Context.Session is availble when the task is run automatically from
the windows scheduler that triggers the Dynamciweb page that triggers the scheduled task to be run.
Maybe you can avoid rendering product in the email template.

BR, Dmitrij

Votes for this answer: 1
 
Søren Jakobsen
Reply

Thanks Dmitriy. If the job runs automatically be the scheduler no errors occurs and mails are send

 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Hello,

I'm so thankful for this forum post because this helped uncover the same situation that we ran into too. We confirmed that it's the same issue where running the scheduled task manually fails due to Dynamicweb.Context.Session not existing. When run from the scheduled runner, it works. It was difficult to track that down.

Can this be reported as a bug so that a solution be put in place? Dynamicweb.Context.Session should be available when running manually too. Note that it has Dynamicweb.Context.Session, but it appears to be a limited set of data. 

Thanks,

Scott

 

 

You must be logged in to post in the forum