3

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

12
  • 1
    I executed the commands, it worked perfectly Dec 22, 2016 at 3:09
  • 1
    I know I know. In this case $list = $List, but you shouldn't change the case when trying to refer to the same variable. Dec 22, 2016 at 13:10
  • 1
    Are all other values set properly? Is it just the Title that's not working? Dec 22, 2016 at 13:26
  • 1
    Please check the following for me: $web = Get-SPWeb "http://servername/" $list = $web.Lists["News & Announcements"] $list.BaseType Dec 22, 2016 at 13:36
  • 1
    @johnG, sorry I was thinking about one thing and typing another. I meant BaseTemplate not BaseType Dec 22, 2016 at 13:45

2 Answers 2

2

@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." 
}
0
1

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.

4
  • you know it is my fault,, i am actually using Discussion Board list not announcement list .... but since our customer asked us to name it "announcement" so i mistype it .. i updated my original question
    – John John
    Dec 22, 2016 at 14:03
  • so using SPUtility.CreateNewDiscussion(SPList, String) can i set the item's modified, created,author, editor fields ?
    – John John
    Dec 22, 2016 at 14:06
  • i am really sorry about the mistype... so now i am not sure if i can pass the editor,author, modified, created fields using SPUtility.CreateNewDiscussion ??seems it only allow passing title..
    – John John
    Dec 22, 2016 at 14:10
  • 1
    You wouldn't believe how often this happens :) Refer to an answer below for the code how to set other values (haven't tested it tho). Dec 22, 2016 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.