Saving content Item

The IPSContentWs.saveItems() does not appears to save the content item in the following scenario. The logic for our this extension is: :

There is a preprocessor extension running. We get the content id from the request session. Load the value in displaytitle for this content item. Next, find the owner for this content item.
Load the owner, and need to copy the displaytitle loaded of itemA to related_url field for owner Item B.

This is the snippet of code:

String s4 = request.getParameter(“sys_contentid”);
String title = request.getParameter(“fieldName_1”);
if (s4 != null && title!=null) {
IPSGuid guid = gmgr.makeGuid(new PSLocator(s4));
try {
List<PSItemSummary> list = cws.findOwners(guid, null, true);
Iterator<PSItemSummary> iter = list.iterator();
while (iter.hasNext()) {
PSItemSummary itemSummary = (PSItemSummary) iter.next();
PSCoreItem item =
loadItemFromPSItemSummary(itemSummary);
//Rhythmyx Impl
ExtensionsUtil.updateItem(item.getContentId(),
“field_Name2”, title);
//PSO Impl
RxItemUtils.setFieldValue(item,
GSAConstants.RELATED_URL_FLD, title);
}
} catch (com.percussion.webservices.PSErrorException e) {
}

public void updateItem(int contentId, String fieldname, String
fieldvalue) throws Exception {
IPSGuid guid = gmgr.makeGuid(new PSLocator(contentId));
List<IPSGuid> guidList = Collections.<IPSGuid> singletonList(guid);
List<com.percussion.services.content.data.PSItemStatus> statusList = cws.prepareForEdit(guidList);
List<PSCoreItem> items = cws.loadItems(guidList, false,
false, false,false);
PSCoreItem item = items.get(0);
PSItemField fld = item.getFieldByName(fieldname);
fld.clearValues();
fld.addValue(new PSTextValue(fieldvalue));

  guidList = cws.saveItems(items, false, true);
  cws.releaseFromEdit(statusList, false);

}

I have shown here both the Rhythmyx Impl save (using updateItem) as well as the PSO Implementation. However, both the save(s) appear not to be doing the save. Can you please tell me if I am missing any API call?

thanks
Manvinder

Go look at the API Recommendations document (http://forum.percussion.com/showthread.php?t=147)

pay particular attention to the description of GUIDs that have revisions vs GUIDs that do not have revisions.

In your case, you are not providing the revision before you save the item. The revision may change on the “prepareForEdit” call (as I explain in the document), so you need to check the edit revision after you’ve checked out the item.

Thanks Dave…for all the information about including the Revisions. Also I reviewed to my best the API Recommendations document that you sent. I do understand I should be passing in the revision along with the content id during the creation of Guid for both the item A as well owner item B.

In your case, you are not providing the revision before you save the item. The revision may change on the “prepareForEdit” call (as I explain in the document), so you need to check the edit revision after you’ve checked out the item

As you mentioned, I am not providing the revision before saving the item, I cannot figure out how should I pass in the revision before the save. The only way I know to save is to invoke the method:
cws.saveItems(items, false, true);

However, I don’t know where can I pass in the revision. This method simply takes a list of PSCoreItems and saves them. Is there a different method?

Also you mentioned I need to check the edit revision after check out of the item. How should I do that? If I get the revision before and after prepareForEdit and if them happen to be same, should I proceed as normal, and if they are different, then what should I do?

Also on the side note…do we need worry about revisions even if we are using PSO methods:
RxItemUtils.setFieldValue()

thanks
Manvinder

Look at the manageRevisions() method of PSServiceLocators class in the API Recommendations sample code, which is describe in section 2.1.3 of the document (on page 7). It shows you how to handle the edit revision.

Basically, you need to make the item GUID from the edit locator AFTER you call prepareForEdit(). This is the GUID you will use for the save.

Dave