Developer forum

Forum » Development » Render page as email returns blank if from Scheduled Task

Render page as email returns blank if from Scheduled Task

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

We have an odd situation and can't figure out why it behaves differently:

 

This all works fine when we change the order state directly in the backend, we are getting an email.

 

However we're triggering this from a scheduled task (because some order data is updated through integration, and a scheduled task looks for necessary changes and triggers an order save event).

 

We tried a number of things without sucess, and having 3 different outcomes is confusing.

 

Any help would be appreciated.

 

Best Regards,

Nuno Aguiar


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Try to print out the area.id and the navigation tag instead of getting the page and render that email page. Then you can see what is wrong.

GetAreaByDomain I guess will return null. On your line 19 you try to get a page - my guess is that it is null. Because no area is found by domain that has that navigation tag. The point of using Navigation tags is that several websites can share the same tag on different areaids and the context resolves the host to an area and then you find the navigation from that.

You are putting this into an orderflow - and there is no context at all... Navigation tag makes no sense in this case. If you want to use navigation tag, it is better to loop all areas and call getbynavigationtag for each area until page is not null.

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

  • We are getting an AreaId
    • Line 17 takes care of that nicely
      var area = pageView != null ? pageView.Area : PageView.GetAreaByDomain() ?? Dynamicweb.Content.Services.Areas.GetAreas().First();
  • The PageID is always accurate. We get it
    • Changing the order state in the backend - always worked fine
    • Running the scheduled task manually - we get the ID, but there's the error I described initially
    • Letting the scheduled task run by itself - we get the ID, but there's the error I described initially

 

I also tried to simply hardcode the pageId, and:

 

So this is definitely odd, that I get these 3 different experiences.

 

Any other ideas?

 

Best Regards,

Nuno Aguiar

 

Any other ideas

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

Picking this back up after Summit, can you cake a look at my comment above and see if there's anything else I can do?

 

It's a bit unfortunate that we cannot use System Emails for this, and the problem seems to be outside of our control.

 

Best Regards,

Nuno Aguiar

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

I have some update on this. Recapping:

  • Our goal is to use System Emails (from Swift) to configure Shipping Confirmation Emails (the customer)
  • There are 3 scenarios where these emails are triggered
    1. Manually updating the order status in the backend - this always worked

      But our situations involve orders being updated through integration, so scheduled tasks trigger the Order State change, in which case
    2. Manually running the scheduled task - we got this to work by using the Pageview instead of the PageViewModel
       
    3. Allowing the scheduled task to run by itself - this still fails

What is failing?

Our conclusion is the PageViewModel is what's not being properly, so the Grids (header, footer and actual content) are not being rendered

 

What other alternatives have we tried?

  • We tried to set a PageViewInfoModel and cast it as a PageViewModel, but that's not possible. 
  • We also can't update the PageViewModel, which could have been a solution.

 

Ultimately seems like the issue is that the PageViewModel is not set accurately (no problems with the Pageview as we initially thought/had).

 

Hope that provides some clarity and helps find a solution.

 

BR

Nuno Aguiar

 

You must be logged in to post in the forum