Developer forum

Forum » Development » Can I compute a default value on save on an item type?

Can I compute a default value on save on an item type?

Martin Skov Nielsen
Reply

Hi.

 

I'm trying to compute a GeoCode from Google Maps when saving a ResellerItem that I've created.

 

Is this possible at all?


Replies

 
Mikkel Ricky
Reply
This post has been marked as an answer

You can subscribe to Dynamicweb.Notifications.Items.Saving and update item data before it's actually being saved.

If your item is created from code, you have to do it in the Save method.

Best regards,
Mikkel

 

 

 

 

 

 

Votes for this answer: 1
 
Martin Skov Nielsen
Reply

Any ideas on how to call subscribe to save when using data integration module?

 
Dmitriy Benyuk
Reply

Hi Martin,
When using the Data Integration module you can subscribe to Dynamicweb.Notifications.Integration.JobFinished Notification. This notification is occured when the job run is finished.
Best regards,
Dmitrij

 
Martin Skov Nielsen
Reply

That just might be right... But... Which dll do I need? I currently get this error The type or namespace name 'Extensibility' could not be found (are you missing a using directive or an assembly reference?)

Also... Is there a way to access the items imported - or do I have to access tha database directly?

 

 
Dmitriy Benyuk
Reply

Hi Martin,
The 'Extensibility' namespace is located in Dynamicweb.dll, it is in the root Dynamicweb.Extensibility.
You can access the database directly or you can use the ItemManager (namespace Dynamicweb.Content.Items).
The item can be found by system name:

        Dim ret As ItemType = Nothing
        Dim metadata As MetadataContainer = Nothing

        If Not String.IsNullOrEmpty(SystemName) Then
            metadata = ItemManager.Metadata.GetMetadata()
            If Not IsNothing(metadata) AndAlso Not IsNothing(metadata.Items) AndAlso metadata.Items.Any() Then
                ret = metadata.Items.Find(SystemName)
               
            End If
        End If

The item can be saved:
ItemManager.Activation.CreateWorkflow(Of ModelFirstActivationWorkflow)().Update(New ItemType() {ItemType})

Regards,
Dmitrij

 
Dmitriy Benyuk
Reply

Also there is some documentation about the Items api here: http://developer.dynamicweb-cms.com/documentation/for-developers/item-based-structure/getting-started.aspx

 
Martin Skov Nielsen
Reply

Is there a nice way to retrieve the connection string? I thinking in the lines of Base.Gs("something") ??

 
Nicolai Høeg Pedersen
Reply

Hi Martin

We do not store the connection string in GlobalSettings.aspx - only parts there of. You can always get the connection string from a connection object, i.e. Database.CreateConnection.ConnectionString.

We build it like this if you are using built in SQL-Server users:

New SqlClient.SqlConnection("User Id=" & Base.GetGs("/Globalsettings/System/Database/UserName") & ";Password=" & Base.GetGs("/Globalsettings/System/Database/Password") & ";Initial Catalog=" & Base.GetGs("/Globalsettings/System/Database/Database") & ";Server=" & Base.GetGs("/Globalsettings/System/Database/SQLServer") & ";Min Pool Size = 5; Max Pool Size=200;")

It might be best to use the connection string property of the connection object - it will work no matter what kind of authentication is used.

BR Nicolai

 
Martin Skov Nielsen
Reply

Thx Nicolai, that was kinda what I was fishing for :)

 

You must be logged in to post in the forum