This code all works fine and the Attempt status returned shows the publish was a success with no errors and the new node set to published.
I then have some code on my website to pull in applications for the logged in user as follows:
var applications = Umbraco.ContentAtXPath("//VacancyApplication[./candidate//Picked[@Key='" + Members.GetCurrentMemberId() + "']]");
The issue is that the newly created and published node is not returned in the query above, it only appears if I go into the administration and click Save And Publish on the node. I have tried updating the cache, etc. within the code to no avail and indeed if I click Republish the entire site in the administration system the node still does not appear and as mentioned I have to actually click Save And Publish on the node to get it to appear.
Does anyone have any ideas as to what the issue may be as I am at a little bit of a loss as to why this could be happening?
I have tried the code you suggest however I am still experiencing the same issue, does anyone have any idea what extra clicking Save and Publish does over publishing a node via the _contentService.Publish and _contentService.SaveAndPublishWithStatus methods?
I have been using the SaveAndPublishWithStatus method (see initial problem higher up this thread), I only used the Publish method based on what another user posted. Either way I still experience the same problem as originally mentioned.
I have been using the SaveAndPublishWithStatus method (see initial problem higher up this thread), I only used the Publish method based on what another user posted. Either way I still experience the same problem as originally mentioned.
I've just tested this using a Services.ContentService.Publish and I can see my new node in the var applications
var applications = Umbraco.ContentAtXPath("//Homepage/Products");
Perhaps the problem is with your XPath (I confess I don't quite understand what your xpath is trying to achieve). Put a breakpoint on this line and drill into the non public members -> _content and can you see the node there? I've tried this with both Publish and SaveAndPublishWithStatus and it seems to be there...
Is it possibly whitespace / illegal chars in your xpath?
The reason I am using ContentAtXpath is two-fold, first is that I am still learning the standard API so wasn' sure how to achieve the above and secondly I have applications that exist within the following type of structure:
A - A school 1 - Live - Job - Application 1 - Application 2 - Pending - Closed - A school 2 B - B school - Live - Pending - Closed - A school 2
What my code needs to do is grab all of the applications no matter where they exist in the tree and that match the current logged in member id. As far as I can surmise and I have tried you code above, that code does not return all applications regardless of where they exist in the tree, whereas ContentAtXpath does. If you can help me try and work out how to do this without using the ContentAtXpath query that would be great.
As you rightly mention, the candidate property type is not an int and is actually stored as a "nuPickers.LuceneDropDownPicker" pre-value. How would I change this to find the right value?
Cool, glad you got it sorted! It's hard to write queries off the top of your head, but I'm glad I pointed you in the right direction. You can do most things via the API :)
Publishing via code issue
Hi,
I am using the following piece of code to create a node within Umbraco 7 (Umbraco version 7.1.4 assembly: 1.0.5261.28127)
This code all works fine and the Attempt status returned shows the publish was a success with no errors and the new node set to published.
I then have some code on my website to pull in applications for the logged in user as follows:
The issue is that the newly created and published node is not returned in the query above, it only appears if I go into the administration and click Save And Publish on the node. I have tried updating the cache, etc. within the code to no avail and indeed if I click Republish the entire site in the administration system the node still does not appear and as mentioned I have to actually click Save And Publish on the node to get it to appear.
Does anyone have any ideas as to what the issue may be as I am at a little bit of a loss as to why this could be happening?
Hi Graham,
Try to add this code. Maybe you have to update document cache?
Thanks
Thanks for the suggestion.
I have tried the code you suggest however I am still experiencing the same issue, does anyone have any idea what extra clicking Save and Publish does over publishing a node via the _contentService.Publish and _contentService.SaveAndPublishWithStatus methods?
Hi Graham,
This method is newest. _contentService.SaveAndPublishWithStatus
Saves and Publishes a single Umbraco.Core.Models.IContent object
This is obsolete: _contentService.SaveAndPublish
Thanks
Hi,
I have been using the SaveAndPublishWithStatus method (see initial problem higher up this thread), I only used the Publish method based on what another user posted. Either way I still experience the same problem as originally mentioned.
Thanks
Hi,
I have been using the SaveAndPublishWithStatus method (see initial problem higher up this thread), I only used the Publish method based on what another user posted. Either way I still experience the same problem as originally mentioned.
Thanks
I've just tested this using a Services.ContentService.Publish and I can see my new node in the var applications
var applications = Umbraco.ContentAtXPath("//Homepage/Products");
Perhaps the problem is with your XPath (I confess I don't quite understand what your xpath is trying to achieve). Put a breakpoint on this line and drill into the non public members -> _content and can you see the node there? I've tried this with both Publish and SaveAndPublishWithStatus and it seems to be there...
Is it possibly whitespace / illegal chars in your xpath?
Why use ContentAtXPath? Why not just use the standard API and see if that returns it? I've done this and it always seems to have worked:
Off top of my head it would be something like this to get every application:
(I'm presuming MemberId is an int).
Hi,
The reason I am using ContentAtXpath is two-fold, first is that I am still learning the standard API so wasn' sure how to achieve the above and secondly I have applications that exist within the following type of structure:
A
- A school 1
- Live
- Job
- Application 1
- Application 2
- Pending
- Closed
- A school 2
B
- B school
- Live
- Pending
- Closed
- A school 2
What my code needs to do is grab all of the applications no matter where they exist in the tree and that match the current logged in member id. As far as I can surmise and I have tried you code above, that code does not return all applications regardless of where they exist in the tree, whereas ContentAtXpath does. If you can help me try and work out how to do this without using the ContentAtXpath query that would be great.
Apologies the query you sent works if I remove the
As you rightly mention, the candidate property type is not an int and is actually stored as a "nuPickers.LuceneDropDownPicker" pre-value. How would I change this to find the right value?
Okay, I have worked out the correct piece of code, see below:
var applications = Model.Content.AncestorOrSelf(1).Descendants("VacancyApplication").Where(x => Convert.ToInt32(x.GetPropertyValue<Picker>("candidate").PickedKeys.FirstOrDefault()) == Members.GetCurrentMemberId());
And I can confirm that this has now resolved the original issue of the node not appearing even though published when using the ContentAtXPath query.
Cool, glad you got it sorted! It's hard to write queries off the top of your head, but I'm glad I pointed you in the right direction. You can do most things via the API :)
is working on a reply...