Hi guys
Recently I created programmatically a post on the Message Boards Portlet and I would like to share this knowledge with you.
The following code retrieve all categories from the Message Boards Portlet.
List categories = MBCategoryLocalServiceUtil.getCategories(themeDisplay.getScopeGroupId());
for(MBCategory category : categories ){
category.getName(); // prints category name
}
To create a post we need the category id, so with the code above you can iterate the categories and select the appropriated category id.
When you have the category, you only need two more parameters, the title and the content of the post. Both are strings.
final long categoryId = ParamUtil.get(request, "category_id", 0); final String title = ParamUtil.get(request, "title", StringPool.BLANK); final String question = ParamUtil.get(request, "question", StringPool.BLANK); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); MBMessage message = MBMessageServiceUtil.addMessage( themeDisplay.getScopeGroupId(), categoryId, title, question, "html", new ArrayList>(), false, 3.0, false, ServiceContextFactory.getInstance(request)); System.out.println( message.getPrimaryKey() );
I recommend you to see the method signature.
If you have any doubts, please post in our forum.
Good luck


