API to Find content item in specified slot

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?

thanks
Manvinder

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:

IPSTemplateSlot slot = asm.findSlotByName(“slotName here”);

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>

thanks
Manvinder

What kind of a slot is it? Is it a manual slot, and auto slot? Something special? Have you tried it with a different slot?

Yes…it is a manual slot that we created. For the same content type, we have 3 different slots…I get similar behavior for all 3 slots.

Did you ever get this working? I have the same need to display the contents of a slot that is not contained on the current tempalte.

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);

Hope this helps.

Thanks Sam, I appreciate your help. Is there any way to accomplish this with Velocity markup?

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:


com.percussion.services.assembly.data.PSAssemblyWorkItem@1a4778a[ m_id=3-101-4111 m_mimeType= m_isDebug=false m_isPublish=true m_resultFile= m_resultData= m_status= m_path=/4111#3 m_parameters={sys_revision=[Ljava.lang.String;@a431f9, sys_siteid=[Ljava.lang.String;@1cd0b2e, sys_foraaslot=[Ljava.lang.String;@99291e, sys_template=[Ljava.lang.String;@1ddaadf, sys_itemfilter=[Ljava.lang.String;@1fd54fa, sys_contentid=[Ljava.lang.String;@15a91b4, sys_relationshipid=[Ljava.lang.String;@113c431, sys_context=[Ljava.lang.String;@1f04d0b} m_variables= m_template=com.percussion.services.assembly.data.PSAssemblyTemplate@1343eb3[ id=875 version=26 name=erauSnContactShortDesc label=S - Contact locationPrefix= locationSuffix= assembler=Java/global/percussion/assembly/velocityAssembler assemblyUrl=../assembler/render styleSheet= aaType=0 outputFormat=2 publishWhen=n templateType=0 description=Snippet rendering with Contact name, short description and position. template=##set($uploadfilephoto_alt = $sys.item.getProperty("uploadfilephoto_alt").String) #set($uploadfilephoto_height = $sys.item.getProperty("uploadfilephoto_height").String) #set($uploadfilephoto_width = $sys.item.getProperty("uploadfilephoto_width").String) #set($dq = '"') ## " #if ( $uploadfilephoto_height && $uploadfilephoto_height != "") #set($img_h_att = " height=${dq}${uploadfilephoto_height}$dq") #end #if ( $uploadfilephoto_width && $uploadfilephoto_width != "") #set($img_w_att = " width=${dq}${uploadfilephoto_width}${dq}") #end 
##
#if($sys.item.hasProperty("rx:biolink"))## #field_if_set("" "rx:Prefix" "")## #field_if_set("" "rx:firstname" "")## #field_if_set("" "rx:middlename" "")## #field_if_set("" "rx:lastname" "")## #field_if_set("" "rx:Suffix" "")## #else## #field_if_set("" "rx:Prefix" "")## #field_if_set("" "rx:firstname" "")## #field_if_set("" "rx:middlename" "")## #field_if_set("" "rx:lastname" "")## #field_if_set("" "rx:Suffix" "")## #end## 
#field_if_set("" "rx:position" "")## #field_if_set("
" "rx:position_role" "
")## #field_if_set("
" "rx:dept" "
")## #field_if_set("
" "rx:company" "
")## #field_if_set("
" "rx:description" "
")## 

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 "

Ok I got it working by using your assembleItem macro, thank you for your help!

Here is the completed code for anyone else wanting to do this:


#set($facFullPageArray = $user.psoSlotTools.getSlotContents($sys.assemblyItem,'erauFacultyFullPage',$params))##
#foreach($page in $facFullPageArray)##
     #set($contactQuoteArray = $user.psoSlotTools.getSlotContents($page,'erauBottomIndex',$params))##
     #foreach($person in $contactQuoteArray)##
           #assembleItem($relresult $person)
           $rx.doc.extractBody($relresult)
      #end
#end