Problem when creating a new Discussion Board item using PowerShell. the item Name for the new item will have the following format “ITEMID_.000”

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/203265

Question

I am working on a Discussion Board list inside SharePoint 2013 on-premise. The Discussion Board list is inside a Team Site collection which have the publishing infrastructure features enabled (both at the site collection and the site level).

We have a couple of old announcements inside our emails and documents which we need to upload inside the Discussion Board list.

so I wrote the following PowerShell script, to add old announcements to the SharePoint Discussion Board list:

$web = Get-SPWeb "http://servername/"  
$list = $web.Lists["News & Announcements"]  
$newItem = $List.AddItem()   
$newItem["Title"] = "Test announcment"  
$newItem["Name"] = "Test announcment" 
$newItem["Body"] = "test body"  
$newItem["Modified"] = "9/3/2015"
$newItem["Created"] = "8/3/2015"  
$user = $web.EnsureUser("\staging.user")  
$newItem["Editor"] = $user  
$newItem["Author"] = $user  
$newItem.UpdateOverwriteVersion() 

Now this PowerShell script will create a new Discussion item with all the specified data correctly, but when I open the new Discussion item I have noted that the item's Name will have the following format "ITEMID_.000", instead of showing the item's title or name (Test Announcement in my case) as when creating a new Discussion item using the UI. here is the result of running the above PowerShell script:

enter image description here

When I click on the item compliance details for the item , I got this where it clearly state that the name is wrong:

enter image description here

So can anyone advice what is going on? And how I can show the Discussion title instead of "ITEMID_.000"?

Thanks

Was it helpful?

Solution

@PaulStrupeikis got it correct. So for powershell, you need to use it as below:

$web = Get-SPWeb "http://servername/" 
$list=$web.Lists.TryGetList("News & Announcements")
if($list -ne $null)
{ 
$newTopic = [Microsoft.SharePoint.Utilities.SPUtility]::CreateNewDiscussion($list, "Test announcment"); 
$newTopic["Body"] = "test body";
$newTopic["Modified"] = "9/3/2015"
$newTopic["Created"] = "8/3/2015"  
$user = $web.EnsureUser("\staging.user")  
$newTopic["Editor"] = $user  
$newTopic["Author"] = $user  
$newTopic.UpdateOverwriteVersion() 

Write-Host $newTopic.Title " discussion topic is created successfully"
}
else
{ 
Write-Host "List does not exists." 
}

OTHER TIPS

John G, your News & Announcements list is using DiscussionBoard template instead of Announcements template. Discussion board is a thread container and the discussions within are threads. You cannot set the title of a thread like that. If you still want to be using DiscussionBoard template, you can create new 'announcements' (well, technically - discussions) by using the following line of code:

SPUtility.CreateNewDiscussion(SPList, String)

More on this HERE

In case you want an announcement list, you should create a new list based on Announcements template. In that case your original code should work fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top