Adding slot using webservices

Hi,
I am migrating our old content into the Rhythmyx and need help in how to add a slot to a content Item. Using the Loader project I am able to add data to the fields but need to know how to add a slot to it.
Thank you.

I’ve added some sample java code to the snippets forum that may help. let me know if you have trouble picking it apart.

In summary, though… you create an array of PSAaRelationship objects and then use the content service to saveContentRelations().

Thanks for the reply.

Can you please write a psudo code if possible.

My requirement is I have two content items itema and itemb. I need to add itemb into a slot of itema.

I am following the order like

        long ida,idb;
        LoadSlotsRequest lsr = new LoadSlotsRequest();
        lsr.Name = "TestSlot";
        psSlot = m_assemblyService.LoadSlots(lsr);
        PSAaRelationship psaRel = new PSAaRelationship();
        
// Need to know how to prepare the items for saving the relation.  
  
        m_contService.PrepareForEdit(new long[2] { ida, idb });

        PSAaRelationship[] lstPSAaRel = new PSAaRelationship[] {psaRel };



        m_contService.SaveContentRelations(lstPSAaRel);

Thanks in advance

Pseudocode:

Do either {
    Set myItem to create new item.
    Set myId to myItem's id.
}
or {
    Set myItemStatus to prepare existing item for update.
    Set myId to myItemStatus' id.
}
Set myRequest to new AddContentRelationsRequest.
Set myRequest's Id to myId.
Set myRequest's Slot to ([i]name of the desired slot[/i]).
Set myRequest's Template to ([i]name of the desired template[/i]).
Set myRequest's RelatedId to ([i]the target item's id[/i]).
Tell the content service to addContentRelations using myRequest.
Do either {
    Check in myId.
}
or {
    Release myId from editing.
}

You only need to load the slot if ItemA isn’t new, and only then if you will be removing a relationship and need to know which relationships you have available to remove.

I found this whole procedure incredibly annoying to use, which is why I built the API interface that I did. Instead of building all these requests and keeping track of IDs that are hard to interpret, I could just create an xml that looked like:

<item id="[i]12345[/i]" xmlns="urn:www.autotrader.com/Rhythmyx/ContentItem">
    <relationship name="[i]TestSlot[/i]">
        <item id="[i]67890[/i]" template="[i]TestTemplate[/i]"/>
    </relationship>
</item>

… and then use my API to build the item, then simply tell the item to save. In most of my own usage, though, I use folder paths and system titles instead of IDs, but if IDs work for you, be my guest.

Kumar - are you using C# version of the WS?
Because Sam is explaining the Java implementation of it.

As far as I understand in order to add a slot you would have to have a subroutine to add new content item in CMS from within your main load process and relate it as a slot to your main item.

I have managed to do the task here is the code snippet

public void AddSlotRelation(long ida, long idb)
{
PSTemplateSlot[] psSlot;
LoadSlotsRequest lsr = new LoadSlotsRequest();
lsr.Name = “TestSlot”;
psSlot = m_assemblyService.LoadSlots(lsr);
PSItem itema = PSWsUtils.LoadItem(m_contService, ida);
PSItem itemb = PSWsUtils.LoadItem(m_contService, idb);
m_contService.PrepareForEdit(new long[2] { ida, idb });

        AddContentRelationsRequest acr = new AddContentRelationsRequest();

        acr.Id = ida;
        acr.Slot = psSlot[0].name;
        acr.RelatedId = new long[1] { idb };
        acr.Template = "TemplateName";
        
        try
        {
            m_contService.AddContentRelations(acr);
        }
        catch(Exception excep)
        {
            
        }
    }

Thanks alot Rushing.

2 things:

[ul][li]You have a superfluous load slot request (you loaded the slot by name just to get the slot’s name… fun times :slight_smile: )
[/li][li]You have checked out itemb when you probably don’t need to. You may want to check on that.[/ul]
[/li]
Neither of these points will affect the outcome of your procedure, however, so take them for what they’re worth.

Just my $0.02.

I have those lines just to see whats returned. I have removed them any way in my final version. I was playing around with the different methods.

Thanks again.