A few days ago, I received an interesting request from a customer. He needed to create Bamboo Discussion Board Plus for SharePoint (DBP) threads and replies programmatically using a PowerShell script. I’m happy to more widely share via this post how to use Windows PowerShell (PS) to automatically create Discussion Board Plus threads and replies.
I’ve divided this post into three parts, and have included the PowerShell script files for your reference. You can download the PS files here first.
1. Create a new Discussion Board Plus (DBP) list for SharePoint:
When you create a new Discussion Board Plus list, please note the list template name in the create window. The name is “Discussion Board Plus.” This is the fixed name and should not be changed.
To create a new DBP list, we call the CreateNewDiscussionBoardPlus method in the CreateDBP.ps1, using the syntax as shown below:
CreateNewDiscussionBoardPlus -url http://server -listName "DBP" -listDescription "DescriptionofDiscussionBoard" -lisTemplate "Discussion Board Plus"
Where:
- URL is your site URL.
- listName is your DBP List Name.
- listDescription is the description of the DBP.
To run the PS file, click on Start -> All Programs -> Accessories -> Windows PowerShell.
After that, you call the CreateDBP file (CreateDBP.ps1) as shown below:
In this example, I set the PS files in the DiscussionBoardPlus_PS_Scripts folder on the desktop. When you see message “your list is created in your site!” in the Windows PowerShell console, this means that your list has been created.
And now, you can check the list that was just created on the site:
2. Create the thread in Discussion Board Plus:
DBP has two content types, which include: BambooDiscussion and BambooMessage:
- BambooDiscussion stands for the thread/topic.
- BambooMessage stands for reply/message.
Some fields are required during the creation of a new thread/topic, such as: ContentType, Title, Body, ThreadIndex, and MessageId. If you want to insert more fields, you have to use their internal names. In this example, the value of ThreadIndex field is a hex string which is made from a complex number so I created a new type and used C# in PS.
To create a new thread, we call the CreateNewThreadDiscussion method in the Create_Thread_DBP.ps1 . It has syntax as shown below:
CreateNewThreadDiscussion -url http://server -listName "DBP" -subject "Subject of the Thread" -body "Body of the Thread"
Where:
- URL is your site URL.
- listName is your DBP List Name.
- subject is the subject of the thread.
- body is the body of the thread.
Next, open your PS console and run Create_Thread_DBP file (Create_Thread_DBP.ps1):
When you see the message, “A new Thread is created successfully in Discussion Board Plus…” in the PowerShell console, this means that the new thread has been created.
After the PS script has run successfully, return to the DBP list and hit F5 to see the result:
3. Create the reply for the existing thread:
In DBP, thread/topic item is a folder item. To create a new reply on the topic, you must know the title of the topic. We use the title to find out the folder and then insert the reply item into a thread. ContentType, ParentFolderId, Body, ThreadIndex, MessageId are all required fields. If you want to insert more fields, you’ll need to use their internal names. ParentFolderId field is Id of the topic, and ThreadIndex field inherits from the topic’s ThreadIndex.
To create a new reply, we call the CreateNewReplyThreadDiscussion method in Create_Reply_Thread_DBP.ps1. It has syntax as shown below:
CreateNewReplyThreadDiscussion -url "http://phong2008:81" -listName "DBP" -threadTitle "Subject of the Thread" -body "Body of the Thread"
Where:
- URL is your site URL.
- listName is your DBP List Name.
- threadTitle is the Title of the thread to which you want to add the reply.
- body is the body of the reply.
Open the PS console and run the Create_Reply_Thread_DBP file (Create_Reply_Thread_DBP.ps1):
When you see the message, “A new reply is created successfully…” in the PowerShell console, this means that the new reply has been created.
After the PS script has run successfully, return to the DBP list and hit F5 to see the result:
Have a nice day!