I have a need to sort all the content items in the slot of the parent content item. The parent has 3 slots. I was trying to fetch all the content items for one of the slot. I tried couple of methods but none got me what I wanted.
First I used the PSO toolkit method:
PSOSlotRelations.getSlotRelations(owner, slot, session)
I passed in the guid of the parent, slot by instantiating the slot using
asm.findSlotByName method. to this I passed in the slot name string.
However, the result set returned was 0.
Then I executed findDependents method. This resulted in fetching contents of all the slots, and there is no way to tell which I belong to which slot.
Any suggestions on the API where I can simply pass in the parent GUID, and the slot name, and get all the content items that are present in the slot?
Invoking PSOSlotRelations.getSlotRelations is yielding an empty list to me. However, invoke of IPSContentWs.findDependents gives the correct list of content items.
Since the getSlotRelations takes 3 parameters, does anyone thinks there could be an issue with session that I am passing. For session parameter, I am doing request.getUserSessionId().
And for the slot, I am creating the IPSTemplate Slot using the following API:
Do you think anything wrong in the way I am passing the slot and session to getSlotRelations() method. Is there any other set I need prior on the IPSTemplateSlot before invoking the getSlotRelations() method>
In the Object-Oriented Java API I uploaded to snippets, I have code in my session wrapper that does a lot of what you need. I’ve listed relavant excerpts of the code here.
First, you’ll want to load the Active Assembly relationship object for the slot (or, optionally, for all slots):
PSAaRelationshipFilter filter = new PSAaRelationshipFilter();
filter.setOwner([i]ownerid[/i]);
filter.setSlot([i]slotName[/i]); [i]// optional. if you leave this off, use rel.getSlot() to determine the slot of the returned relationships[/i]
filter.setLimitToOwnerRevisions(true);
LoadContentRelationsRequest req = new LoadContentRelationsRequest(filter, false);
PSAaRelationship[] rels = getContentService().loadContentRelations(req);
You’ll want to use this array of PSAaRelationship to fetch dependent content items. Then you’ll want to sort the relationships based on their dependents’ data.
If you’re going to be saving the results of your sort back to the repository, you’ll want to do this:
ReorderContentRelationsRequest req = new ReorderContentRelationsRequest(null, 0);
long[] ids = new long[rels.length];
for (int i = 0; i < rels.length; i++) {
ids[i] = rels[i].getId();
}
req.setId(ids);
getContentService().reorderContentRelations(req);
ROTFL! I had a velocity version of all this typed in first, but then I read the title of the thread again and thought you wanted API calls. Sure there is…
I’ve got a couple of macros over on the Snippets forum that you can use to do this:
#[initcustomslot](https://community.percussion.com/t/custom-slot-macro/3974)( "[i]slotName[/i]" "[i]additionalQueryParams[/i]" )
[i]## insert your sorting code here[/i]
#[I]sortAsmItems[/I]( $sys.currentslot.assemblyItems )
[i]##display the results[/i]
#foreach( $item in $sys.currentslot.assemblyItems )
#[assembleItem](https://community.percussion.com/t/macros-to-assemble-arbitrary-content-items-inside-other-templates/3975)( $relresult $item )
$rx.doc.extractBody($relresult)
#end
#endslot( "[i]slotName[/i]" )
If you want to be able to use Active Assembly on the output, you’ll want to add a bunch of extra active assembly macros to wrap the output, but you can rip all that from #slot() in the system macro file.
Caveat! $sys.index may have the original index when assembling the related items instead of the new one (I have not tested to find out for sure), so be careful.
Stephen, all slots for any template allowed for the content type are accessible to any template for that content type (at least, last time I checked - which was a few patches ago in 6.5.2). If you need to access the related items of a completely different content item, you can build an assembly item for it, then you can use $user.psoSlotTools.getSlotContents() to get an array of items related to it.
I really appreciate your help and I am starting to see how this could work, however maybe you can help me pick apart this problem.
I have a landing page that has a slot called “erauFacultyFullPage”, which holds one item, the full generic page that has a slot for a faculty spotlight. This faculty spotlight slot is what I want to get the items from, so doing a simple initslot(‘erauFacultyFullPage’) on the landing page and displaying the results reveals the page assembly information with the slot.
Do I need to assemble the page if I already have all of the assembly information? I was thinking I could do something like this:
#initslot('erauFacultyFullPage')##
#foreach($result in $sys.currentslot.relresults)##
$user.psoSlotTools.getSlotContents($result,'erauBottomIndex',"template=erauSnContactQuote")
#end
But that is not working. I tried to use your code to assemble the item from the content id but that did not produce any results. Can you see what I am doing wrong?
I also tried doing something like this:
#initslot('erauFacultyFullPage')##
#foreach($result in $sys.currentslot.relresults)##
#assembleItem($relresult $result)
#initslot('erauBottomIndex')##
#foreach($result in $sys.currentslot.relresults)##
$rx.doc.extractBody($relresult)
#end
#end
Stephen, $sys.currentslot.relresults is an array of strings.
The “right” way would be to build a Local Template for the Full Page content type that displays what you need to display. However, this may not meet your needs exactly… you could also do something like:
#set( $facFullPageArray = $user.psoSlotTools.getSlotContents($sys.assemblyItem,'erauFacultyFullPage','') )
#foreach($page in $facFullPageArray)##
#set( $contactQuoteArray = $user.psoSlotTools.getSlotContents($page,'erauBottomIndex',"template=erauSnContactQuote")
## do something with the assembly items in $contactQuoteArray
#end
That is working for me, however I just want to display the item in the associated template, I tried using $rx.doc.extractBody but got this message, “Problem assembling output for item: 4-101-6867 with template: erauPgHomepageCOB exception: null see log for stack trace”.
Here is what the code I used:
#set($facFullPageArray = $user.psoSlotTools.getSlotContents($sys.assemblyItem,'erauFacultyFullPage',$params))##
#foreach($page in $facFullPageArray)##
#set($contactQuoteArray = $user.psoSlotTools.getSlotContents($page,'erauBottomIndex',$params))##
## do something with the assembly items in $contactQuoteArray
#foreach($person in $contactQuoteArray)##
$person
##$rx.doc.extractBody($person)
#end
#end
The $person variable contains the correct assembly items:
I just want to use the item in it’s template "m_template=com.percussion.services.assembly.data.PSAssemblyTemplate@1343eb3[ id=875 version=26 name=erauSnContactShortDesc label=S - Contact "