Accessing the state of a content item in web services

Hi

I like to know what state the content item is assigned to before running an update process. This is so the item is only updated when on the public state.

I can use PrepareForEdit but this checks the content out. Is is possible to find this out without checking the content out?

Private Sub UpdateContentItem(ByVal Contact As DataRow)

        Dim ContentID As Int32, ContentItemStatus As PSItemStatus, ContentItem As PSItem

        Try
            ContentID = Contact("contentid")
            ContentItemStatus = Utility.PrepareForEdit(_ContentSVC, ContentID)
            ContentItem = Utility.LoadItem(_ContentSVC, ContentID)
            For Each ContentItemField In ContentItem.Fields
              .....
            Next

            Call Utility.CheckInItem(_ContentSVC, ContentID)
            Call Utility.TransitionItem(_SystemSVC, ContentID, "Return to Public")
            Call Utility.TransitionItem(_SystemSVC, ContentID, "Force Public")

Cheers
James

James,

We recommend that you use the findItems() method. This will perform a search. Set the search criteria to use sys_contentid and the content id.

In the search result fields, you can add the fields named “sys_statename” and “sys_publishabletype”. These fields will tell you the name of the state and whether it is a public state or not.

Dave

Hi Dave

When do the search results fields get set? I’m having trouble added them. I can get the state id as that’s returned as standard bit if I create a SearchResultField instance and set it’s name how then is that added to the list of PSSearchResultsFields()?

Public Shared Function GetContentItemStateName(ByVal ContentService As contentSOAP, ByVal ContentID As Integer) As String

        Dim FindItemsRequest As New FindItemsRequest
        Dim Search As New PSSearch
        Dim SearchParams As New PSSearchParams
        Dim SearchField As New PSSearchField
        Dim SearchResults As PSSearchResults()
        Dim SearchResultField As New PSSearchResultsFields
        Dim SearchResultsFields As New PSSearchResultsFields()
        Dim SearchResult As New PSSearchResults
        Dim strStateName As String = ""

        SearchField.name = "sys_contentid"
        SearchField.Value = ContentID

        SearchParams.Parameter = New PSSearchField() {SearchField}
        Search.PSSearchParams = SearchParams
        FindItemsRequest.PSSearch = Search

        SearchResultField.name = "sys_statename"

        SearchResults = ContentService.FindItems(FindItemsRequest)

        If SearchResults.Length = 1 Then
            strStateName = SearchResults(0).Fields(6).Value
        End If

        Return strStateName
    End Function

Cheers
James

I’ve only done this in Java, not .NET, so I can’t help you with syntax, but what you have to do is:

Add the SearchResultField to the SearchResultFields array.

Add the SearchResultFields array to SearchParams. In Java you call the PSSearchParams.setSearchResults() method, passing the SearchResultFields array variable.

Dave