PSContentNode from sys_contentid

I’m trying to get a PSContentNode for a content item from a sys_contentid. I’ve had some success with this:

#set ($itemGuid = $user.psoObjectFinder.getGuidById($sys_contentid))
#set ($itemNode = $user.psoObjectFinder.getNodeByGuid($itemGuid))

This gives me a PSContentNode, but no local fields are included in the properties, only the system fields. Is there a better way to do this or should I just be resorting to a JSR query to access the fields?

It looks like like the local field values are not loaded if the Version number is not specified.

Try adding the revision:


#set ($itemGuid = $user.psoObjectFinder.getGuidById($sys.item.getProperty("sys_contentid").String, $sys.item.getProperty("sys_revision").String))
#set ($itemNode = $user.psoObjectFinder.getNodeByGuid($itemGuid))

I added a quick example here: getproperties example (the JQuery Mobile is unnecessary - I was just having fun with it)

[QUOTE=junwin;20927]I’m trying to get a PSContentNode for a content item from a sys_contentid. I’ve had some success with this:

#set ($itemGuid = $user.psoObjectFinder.getGuidById($sys_contentid))
#set ($itemNode = $user.psoObjectFinder.getNodeByGuid($itemGuid))

This gives me a PSContentNode, but no local fields are included in the properties, only the system fields. Is there a better way to do this or should I just be resorting to a JSR query to access the fields?[/QUOTE]

Thanks, Nate. That makes sense about the revision in the Guid.

Unfortunately, in my current context, I only have the sys_contentid. I suppose I could run my original code and get the current revision from the node, then run it again inserting that revision.

I did have some success using psoQueryTools.executeQueryNodes. I’m not sure if this is a particularly efficient way, but it does the job. I created this velocity macro, which may be useful to someone:

## Runs Query to get a content node from a content id. Returns Node as "$myNode" for use in Velocity template
## Params $myItemId: sys_contentid, $myContentType: name of content type. Example: #getnodefromid ("1234" "rffGeneric")
#macro(getnodefromid $myItemId $myContentType)##
	#set ($myNodeQuery = "select rx:sys_contentid from rx:" + $myContentType + " where rx:sys_contentid='" + $myItemId + "'")##
	#set ($myNodeResult = $user.psoQueryTools.executeQueryNodes($myNodeQuery,1,null,null))##
	#set ($myNode = $myNodeResult.nextNode())##
#end##

Hi,

You’d have to test the performance of it compared to the query, but it may be better performing to read the revision property of the content node loaded with no local fields, and then create a second guid with the revision, and then reloading the the node with that Guid to get the local fields.

Everything except the local field data will be cached so the 2nd request should be pretty quick.


#set ($itemGuid = $user.psoObjectFinder.getGuidById($sys.item.getProperty("sys_contentid").String))##, $sys.item.getProperty("sys_revision").String))
#set ($itemNode = $user.psoObjectFinder.getNodeByGuid($itemGuid))
#set ($revision = $itemNode.getProperty("rx:sys_revision").getValue().String)
#set ($itemGuid = $user.psoObjectFinder.getGuidById($sys.item.getProperty("sys_contentid").String,$revision))##, $sys.item.getProperty("sys_revision").String))
#set ($itemNode = $user.psoObjectFinder.getNodeByGuid($itemGuid))

-n

[QUOTE=junwin;20932]Thanks, Nate. That makes sense about the revision in the Guid.

Unfortunately, in my current context, I only have the sys_contentid. I suppose I could run my original code and get the current revision from the node, then run it again inserting that revision.

I did have some success using psoQueryTools.executeQueryNodes. I’m not sure if this is a particularly efficient way, but it does the job. I created this velocity macro, which may be useful to someone:

## Runs Query to get a content node from a content id. Returns Node as "$myNode" for use in Velocity template
## Params $myItemId: sys_contentid, $myContentType: name of content type. Example: #getnodefromid ("1234" "rffGeneric")
#macro(getnodefromid $myItemId $myContentType)##
	#set ($myNodeQuery = "select rx:sys_contentid from rx:" + $myContentType + " where rx:sys_contentid='" + $myItemId + "'")##
	#set ($myNodeResult = $user.psoQueryTools.executeQueryNodes($myNodeQuery,1,null,null))##
	#set ($myNode = $myNodeResult.nextNode())##
#end##

[/QUOTE]