The following code did the trick.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[CIP_GenerateCIPNews]
@ModuleId int,
@Title varchar(150),
@Description varchar(1000),
@Article varchar(8000),
@PostStartDate datetime,
@PostEndDate datetime,
@PortalId int,
@CreatedByUser int,
@CreatedDate datetime
AS
DECLARE @AdministratorId int
SET @AdministratorId = 2
DECLARE @TabId int
DECLARE @TabViewPermissionId int
DECLARE @TabEditPermissionId int
DECLARE @AdminRoleId int
DECLARE @CIPNewsModuleDefId int
DECLARE @CIPNewsModuleId int
DECLARE @HTMLModuleDefId int
DECLARE @HTMLModuleId int
DECLARE @ModuleViewPermissionId int
DECLARE @ModuleEditPermissionId int
INSERT INTO CIPNews (
ModuleId,
Title,
Description,
PostStartDate,
PostEndDate,
PortalId,
CreatedByUser,
CreatedDate
)
VALUES (
@ModuleId,
@Title,
@Description,
@PostStartDate,
@PostEndDate,
@PortalId,
@CreatedByUser,
getdate()
)
-- Get the identity of newly added CIPNews item
SELECT @CIPNewsModuleId = SCOPE_IDENTITY()
-- Get the Module Definition for the CIPNews Module
SELECT @CIPNewsModuleDefId = ModuleDefId
FROM ModuleDefinitions
WHERE FriendlyName='CIPNews'
-- Get the Module Definition for the HTMLNews Module
SELECT @HTMLModuleDefId = ModuleDefId
FROM ModuleDefinitions
WHERE FriendlyName='Text/HTML'
-- Create a new instance of the HTML/Text Module, return primarykey in @HTMLModuleId
INSERT INTO Modules (
PortalId,
ModuleDefId,
ModuleTitle,
AllTabs,
Header,
Footer,
StartDate,
EndDate,
InheritViewPermissions,
IsDeleted
)
VALUES (
@PortalId,
@HTMLModuleDefId,
@Title,
0,
null,
null,
null,
null,
1,
0
)
SELECT @HTMLModuleId = SCOPE_IDENTITY()
-- Insert Article into HTML/Text Module Instance
INSERT INTO HTMLText (
ModuleID,
DesktopHtml,
DesktopSummary,
CreatedByUser,
CreatedDate
)
VALUES (
@HTMLModuleId,
@Article,
@Title,
@CreatedByUser,
@CreatedDate
)
--create a new Tab for the conversion
INSERT INTO Tabs (
PortalId,
TabName,
IsVisible,
DisableLink,
ParentId,
IconFile,
Title,
Description,
KeyWords,
IsDeleted,
Url,
SkinSrc,
ContainerSrc,
TabPath,
StartDate,
EndDate
)
values (
@PortalId,
@Title,
0,
0,
null,
'',
@Title,
'',
'',
0,
'',
null,
null,
'//CIPNews',
@CreatedByUser,
@CreatedDate
)
SELECT @TabId = SCOPE_IDENTITY()
-- Get the administrator roleid
SELECT DISTINCT @AdminRoleId = RoleId
FROM Roles
WHERE RoleName = 'Administrators'
AND PortalId = @PortalId
-- Get the Permission IDs for the Tab & Module
SELECT DISTINCT @TabViewPermissionId = PermissionId
FROM Permission
WHERE PermissionCode = 'SYSTEM_TAB'
AND PermissionKey = 'VIEW'
SELECT DISTINCT @TabEditPermissionId = PermissionId
FROM Permission
WHERE PermissionCode = 'SYSTEM_TAB'
AND PermissionKey = 'EDIT'
SELECT DISTINCT @ModuleViewPermissionId = PermissionId
FROM Permission
WHERE PermissionCode = 'SYSTEM_MODULE_DEFINITION'
AND PermissionKey = 'VIEW'
SELECT DISTINCT @ModuleEditPermissionId = PermissionId
FROM Permission
WHERE PermissionCode = 'SYSTEM_MODULE_DEFINITION'
AND PermissionKey = 'EDIT'
--Add View permissions for the Tab
INSERT INTO TabPermission
(TabId,PermissionId,RoleId,AllowAccess)
VALUES (@TabId,@TabViewPermissionId,@AdminRoleId,1)
--Add Edit permissions for the Tab
INSERT INTO TabPermission
(TabId,PermissionId,RoleId,AllowAccess)
VALUES (@TabId,@TabEditPermissionId,@AdminRoleId,1)
--Add View permissions for the Module
INSERT INTO ModulePermission
(ModuleId,PermissionId,RoleId,AllowAccess)
VALUES (@HTMLModuleId,@ModuleViewPermissionId,@AdminRoleId,1)
--Add Edit permissions for the Module
INSERT INTO ModulePermission
(ModuleId,PermissionId,RoleId,AllowAccess)
VALUES (@HTMLModuleId,@ModuleEditPermissionId,@AdminRoleId,1)
--add the HTML/Text Module to the Tab
INSERT INTO TabModules (
TabId,
ModuleId,
PaneName,
ModuleOrder,
CacheTime,
Alignment,
Color,
Border,
IconFile,
Visibility,
ContainerSrc,
DisplayTitle,
DisplayPrint,
DisplaySyndicate
)
VALUES (
@TabId,
@HTMLModuleId,
'ContentPane',
1,
0,
null,
null,
null,
null,
0,
null,
1,
0,
0
)
Thanks to
John Mitchell's blog