Developer forum

Forum » Development » Custom Extranetuser fields aren't read by DW7

Custom Extranetuser fields aren't read by DW7


Reply
Hello fellow developers,

Recently a customer contacted us, saying that the changes she made to the extranet users customfields didn't apply to the frontend.

I looked into the the matter, and found that the custom module we made, which fetches data from a users custom fields, returned different data than what was set in the Extranet for a given user.

The code that fetches custom fields uses this code:
Extranet user = PageView.Current().User;
string customField = user.get_Information("customField").ToString();

This returned to my a value that i could not find in the users custom fields.

I figured that something had changed with the new User Management, so i tried changing my code to the following:

Dynamicweb.Modules.UserManagement.User user = Dynamicweb.Modules.UserManagement.User.GetCurrentUser();
string customField2 = user.CustomFieldValues.Find(p => p.CustomField.SystemName.Equals("customField")).Value.ToString();


This returned the value that i saw in the User Management center

I took a look in the database for a give user and in the column "AccessUserInformation" i found the values that we returns when using the get_Information() method, and in the column customField i found the value returned by the new UserManagement class.

Ofc. i could just change my code to use the new method, but then all my correct data which is stored in the AccesUserInformation field is lost, and i dont want that.

Any ideas in how to fix this problem?

Regards
 Martin



Replies

 
Nicolai Høeg Pedersen
Reply

When migrating from old extranet/user management to new one, you ran a conversion wizard. That wizard should have migrated custom fields and their values to the new format.

I can provide you the code that does this in the conversion wizard:

 Private Sub ConvertExtranetCustomFields(ByVal isResume As Boolean)
            If Not isResume Then
                'Get old extranet custom fields. These are stored on the user 'Administrator'
                Dim infos As IEnumerable(Of AccessUserInformationInfo)
                Try
                    Dim xmlString As String = Base.ChkString(Database.ExecuteScalar("SELECT AccessUserInformation FROM AccessUser WHERE AccessUserID = 2", "Access.mdb"))
                    infos = GetAccessUserInformations(xmlString)
                Catch
                    Return
                End Try
                For Each info As AccessUserInformationInfo In infos
                    Dim customField As New Dynamicweb.Modules.Common.CustomFields.CustomField(info.SystemName, "AccessUser", Dynamicweb.Modules.Common.CustomFields.CustomFieldType.Types.Text)
                    customField.Name = info.Name
                    Try
                        customField.Save()
                    Catch ex As Exception
                        'Continue
                    End Try
                Next
                Dim allCustomFields As Dynamicweb.Modules.Common.CustomFields.CustomFieldCollection = Dynamicweb.Modules.Common.CustomFields.CustomField.GetCustomFields("AccessUser", "Access.mdb")
                If allCustomFields.Count = 0 Then
                    Return
                End If
            End If

            Dim dirtyUsers As New UserCollection()
            Using userReader As Data.IDataReader = Database.getDataReader(String.Format("SELECT * FROM AccessUser WHERE AccessUserID BETWEEN {1} AND {2} ", UserTypeString, StartID, EndID), "Access.mdb")
                While userReader.Read()
                    If String.IsNullOrEmpty(Base.ChkString(userReader("AccessUserInformation"))) OrElse IsCorrectUserType(Base.ChkInteger(userReader("AccessUserType"))) Then
                        Continue While
                    End If

                    'Make the user from our row
                    Dim user As New Dynamicweb.Modules.UserManagement.User()
                    user.Fill(userReader)


                    Dim dirty As Boolean = False
                    For Each info As AccessUserInformationInfo In GetAccessUserInformations(Base.ChkString(userReader("AccessUserInformation")))
                        For Each customFieldValue As Dynamicweb.Modules.Common.CustomFields.CustomFieldValue In user.CustomFieldValues
                            If customFieldValue.CustomField.SystemName = info.SystemName Then
                                'Only update and set dirty if the fields are different (a good chance both fields are empty string)
                                If Base.ChkString(customFieldValue.Value) <> info.Value Then
                                    customFieldValue.Value = info.Value
                                    dirty = True
                                End If
                                Exit For
                            End If
                        Next
                    Next

                    If dirty Then
                        dirtyUsers.Add(user)
                    End If

                End While
            End Using
            For Each user As Dynamicweb.Modules.UserManagement.User In dirtyUsers
                user.Save()
            Next
        End Sub

Private Function GetAccessUserInformations(ByVal xmlString As String) As IEnumerable(Of AccessUserInformationInfo)
            Dim infos As New List(Of AccessUserInformationInfo)()
            Dim xmlDoc As New System.Xml.XmlDocument()

            Try
                xmlDoc.LoadXml(xmlString)
            Catch
                Return infos
            End Try

            For Each field As System.Xml.XmlElement In xmlDoc.SelectNodes("//AccessUserInformationField")
                Try
                    Dim systemName As String = field.Attributes("name").Value
                    Dim name As String = ""

                    Try
                        name = field.SelectSingleNode("title").InnerText
                    Catch
                    End Try

                    Dim value As String = ""
                    Try
                        value = field.SelectSingleNode("value").InnerText
                    Catch
                    End Try

                    Dim info As New AccessUserInformationInfo()
                    With info
                        .Name = name
                        .SystemName = systemName
                        .Value = value
                    End With

                    infos.Add(info)

                Catch
                End Try
            Next

            Return infos
        End Function

Private Class AccessUserInformationInfo
            Public Name As String
            Public SystemName As String
            Public Value As String
        End Class

 
Reply
Hi Nicolai,

Would importing the user again fix our problem?

Regards
 Martin


 
Nicolai Høeg Pedersen
Reply
Maybe it could - but no promises.

Login to the administration, and go the url of the browser and enter

/Admin/Module/Usermanagement/ConversionWizard.aspx and run it again. See what happens.
 
Reply
I tried calling the url, but all i get is a blank site. Nothing seems to happen.

What i meant before was, if it would help to import our users again via the Import/Export module.

Is this module updated to import to the correct fields?

Regards
 Martin
 
Nicolai Høeg Pedersen
Reply
The pipeline has not been updated to use the new custom field method. So no.
 
Reply
Hi Nicolai,

When can we expect this to be updated, so we can correct the problem?

We basicly now have tons of extranet users, imported via the Import/Export module, but none of their custom information is shown.

Importing again didn't work, running the wizard wasn't possible, and i don't see why we should make any custom code to fix this, since the users where imported via your module, which should be safe to use.

What do we do to fix this problem?

Regards
 Martin
 
Nicolai Høeg Pedersen
Reply
The activity update has been bugged as TFS 5609 and will be fixed very soon.

Mail me a case number or a url to the solution - then we will take a look at the issue.

 

You must be logged in to post in the forum