Jump to content

Problem with UserEntry.SetPhoneBook(...)


tniercke

Recommended Posts

Hi all,

 

I try to set a swyx user's personal phonebook using the following code.

It is intended, that the user's phonebook is cleared before, so I thought to use the UserEntry.SetPhoneBook(...)

bacause it reads that the current phonebooki of the user will be emptied during the function call.

 

I do run into a null-reference exception I cannot explain or find out where it rises...

Seems to be inside some CDS-SDK Library.

I am remote-debugging on a Swyx-Testsystem, so I cannot "dive" into those Swyx-Libraries...

 

Do I miss something or is it a bug ?

 

<code>

Public Function InsertToUserPhonebook(sEmailAddr As String, lstPhoneBookEntries As List(Of PhonebookEntry))

 

        Dim usr As SWConfigDataClientLib.Proxies.Users.UserEntry = Me.GetSwyxUser(sEmailAddr)

        '======================================================================
        Try
            ' Get User Phonebook
            'usr.SetPhoneBook() 'Achtung: das PhoneBook wird vorher geleert !!!
            Dim pbeCollection As SWConfigDataClientLib.Proxies.Users.PhoneBookEntryCollection = New PhoneBookEntryCollection()

            For Each phonebookentry In lstPhoneBookEntries
                Dim pbe As SWConfigDataClientLib.Proxies.Users.PhoneBookEntry = New Proxies.Users.PhoneBookEntry()
                pbe.Name = phonebookentry.Name
                pbe.Number = phonebookentry.Number
                pbe.SearchNumber = phonebookentry.Number
                pbe.Hide = False
                pbeCollection.Add(pbe)
            Next
            ' This call fails with a null-reference exception.
            ' But neither usr or pbeCollection (or it's items) are null...

            usr.SetPhoneBook(pbeCollection)

        Catch ex As Exception
            _logger.Log("*** EXCEPTION in CFISSwyxHelper.UpdateOrCreateUserPhonebookEntries ***" & vbCrLf & ex.Message)
            Return False

        End Try
        Return True

End Function
</code>

 

If I try the following analogue to editing the gl o bal phonebook, the ite m s are stored in the global phonebook.

I do miss a function like ModifyPhoneBookEntry  and AddPhoneBookEntry for the user phonebook.

Or maybe I lack some knowledge. Anyone willing to help me out is highly welcome.

 

<code>

var userenumAll = _LibManager.GetUserEnum();
userenumAll.ExecuteIDFilter(usr.UserID)

;
var
userenum = userenumAll.GetObjectByPrimaryKey(usr.UserID) ;
var
upbenum = _LibManager.GetUserPhoneBookEnum();

foreach (phonebookentry In lstPhoneBookEntries) {


  var upbxpb = userenum.GetPhoneBook(phonebookentry.Name).CreateSortableFilterCollection() ;
 
if (upbxpb.Count != 0) {
    upbenum.ModifyEditablePhoneBookEntry(upbxpb.FirstOrDefault().EntryID, phonebookentry.Name,
                phonebookentry.Number, phonebookentry.Number,
phonebookentry.Description, False) ;
  } e
lse {
      upbenum.AddEditablePhoneBookEntry(phonebookentry.Name, phonebookentry.Number,
                        phonebookentry.Number, phonebookentry.Description, False);
  }
}
upbenum.Update();

</code>

 

Greets

Thomas

Link to comment
Share on other sites


  • 4 weeks later...
  • Most Valued User

Hello Thomas,

 

the following code snippet should help you to achieve your goal:

 

public void ImportPersonalPhonebook(int userId, List<YourCustomTransportClass> newPersonalPhonebookData, bool clearUserPhonebook)
{
    var userPhoneBookEnum = this.libManager.GetUserPhoneBookEnum();

    try
    {
        // Load personal phonebook of the user
        userPhoneBookEnum.ExecuteFilterAll(userId, new OrderByList());
       
        // Clear personal phonebook if requested
        if (clearUserPhonebook)
        {
            userPhoneBookEnum.PrimaryCollection.RemoveAll();
            userPhoneBookEnum.Update();
        }

        // Add new personal phonebook entries to the primary collection
        foreach (var entry in newPersonalPhonebookData)
        {
            var newUserPhoneBookEntry = new UserPhoneBookEntry()
            {
                Name = entry.Name,
                Number = entry.Number,
                SearchNumber = entry.Number,
                UserID = userId
            };
            
            bool isHidden;
            if (Boolean.TryParse(entry.Hide, out isHidden))
            {
                newUserPhoneBookEntry.Hide = isHidden;
            }
            
            userPhoneBookEnum.PrimaryCollection.Add(newEntry);
        }

        // Save the changes to the database
        userPhoneBookEnum.Update();
    }
    catch (Exception ex)
    {
        <Your Exception Handling>
    }
    finally
    {
        // Free resources
        if (userPhoneBookEnum != null)
        {
            userPhoneBookEnum.FreeForReuse();
        }
    }
}
Link to comment
Share on other sites


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.