I can't find anything on google on this. I've created an item as follows:
$item = $supportPackList.Items.Add()
$item["Title"] = $supportPackName
$item["Job No (Nav)"] = "NOT MAPPED TO NAV"
$item["SupportPackTemplateLookup"] = $supportPackTemplateId
$item["ClientLookup"] = $clientTemplateId
$item["Description (Nav)"] = "NOT MAPPED TO NAV"
$item.Update()
This works. I can see it through the UI and also change properties/save it again. Now, after creating the item, this works:
$suppPackList.GetItemById(22).Title
I am then trying to update it through powershell. However, this simple line;
$suppPackList.GetItemById(22).Update()
Or even
$suppPackList.GetItemById(22).SystemUpdate()
Gives me:
Exception calling "SystemUpdate" with "0" argument(s):
"System.ArgumentException: Item does not exist. It may have been deleted by
another user.
at Microsoft.SharePoint.SPList.GetItemById(String strId, Int32 id, String
strRootFolder, Boolean cacheRowsetAndId, String strViewFields, Boolean
bDatesInUtc, Boolean bExpandQuery)
at Microsoft.SharePoint.SPList.GetItemById(String strId, Int32 id, String
strRootFolder, Boolean cacheRowsetAndId, String strViewFields, Boolean
bDatesInUtc)
at Microsoft.SharePoint.SPList.GetItemById(String strId, Int3"
At line:1 char:1
+ $suppPackList.GetItemById(22).SystemUpdate()
Of course it exists, you just gave me it's Title! Note that updating the item from the Edit Form in the UI by clicking Save works. I have some event receiver code. Here's the gist of it, but technically, if I can do something through the UI I should be able to do it via power shell right?
public override void ItemUpdating(SPItemEventProperties properties)
{
using (DisabledEventsScope scope = new DisabledEventsScope())
{
SPL_SupportPack supportPack = new SPL_SupportPack(properties.AfterProperties);
try
{
base.ItemUpdating(properties);
UpdateExistingSPSupportPack(supportPack, properties.Web);
}
catch (Exception e)
{
//SPUtility.TransferToErrorPage(e.ToString());
properties.ErrorMessage = e.ToString();
properties.Status = SPEventReceiverStatus.CancelWithError;
}
}
}
One more thing, I have my debugger attached to all w3wp.exe processes. Updating through UI triggers the ItemUpdating(), but through power shell doesn't (for both .Update() and .SystemUpdate().
I've been tearing my hair over this, I must be missing something very basic. Any ideas?