Hi, I want to develop a module that needs a setting in PortalSettings table. In the installing script I want to insert the row but how can I specify the current PortalId in which the module is being installing?
Thanks in advance.
As Joe states there is no 'current' portal when installing a module - but if you 'just' need a valid portal id you can fetch the first available. Fill in the rest of the fields as needed - and remember to take the database scheme into consideration (the curly brackets part).
INSERT INTO {YourDatabase}.{dbo}.[PortalSettings] ([PortalID] ,[SettingName] ,[SettingValue] ,[CreatedByUserID] ,[CreatedOnDate] ,[LastModifiedByUserID] ,[LastModifiedOnDate] ,[CultureCode] ,[IsSecure]) VALUES ((SELECT TOP (1) [PortalID] FROM {YourDatabase}.{dbo}.[Portals] ORDER BY [PortalID]) ,@SettingName, nvarchar(50), ,@SettingValue, nvarchar(max), ,@CreatedByUserID, int, ,@CreatedOnDate, datetime, ,@LastModifiedByUserID, int, ,@LastModifiedOnDate, datetime, ,@CultureCode, nvarchar(10), ,@IsSecure, bit,)
Hi Joe,
thanks for the answer. I wanted to give an initialize value to a portalsettings for my module, but, if I have no references to the current Portal, I can do what DnnBro suggested.
Thanks.
I would just do something like
// This is pseudocode, not c#! protected string DefaultValueForMyModule { get { object o = PortalController.GetPortalSetting(PortalId, "DefaultValueForMyModule"); if (o == null) { return "DefaultValue"; } return o.ToString(); } }
Happy DNNing! Michael
Michael TobischDNN★MVP
You can use a technique like this:
https://github.com/hotcak...troller.cs#L381-L390
You should just be aware that DNN instances that contain thousands of portals exist. Anytime this is the case, such a technique might not be the best way to do this.
These Forums are dedicated to the discussion of DNN Platform.
For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:
Awesome! Simply post in the forums using the link below and we'll get you started.