AnsweredAssumed Answered

AFNotificationContactTemplate.FindNotificationContactTemplatesByContact() is not able to find the Email end point

Question asked by Jagan on Feb 19, 2019
Latest reply on Feb 22, 2019 by Jagan

Hello!

AFNotificationContactTemplate.FindNotificationContactTemplatesByContact() is not able to find the Email end point even though, I can see it from AF Explorer contact search. What might be causing this?

 

More details below. All PI versions are from "PI Server 2018".

 

Code

            // This is returning contacts and as well all AD groups. Not sure if returning AD Groups is intentional

             AFNamedCollectionList<AFContact> allContacts = AFContact.FindContacts(afdbContext.System, null, AFSearchField.Name, AFSortField.Name, AFSortOrder.Ascending, int.MaxValue);

            Logger.Info($"{log}Total contacts count: {allContacts.Count}");

            IEnumerable<AFContact> allUsers = allContacts.Where(a => a.ContactType == AFContactType.User).ToList();

            Logger.Info($"{log}Count after considering only contacts of type user: {allUsers.Count()}");

 

                    foreach (AFContact user in allUsers)

            {

                // Know that this obsolete but still using it

                 AFNamedCollectionList<AFNotificationContactTemplate> ncts = AFNotificationContactTemplate.FindNotificationContactTemplatesByContact(user, AFSortField.ID, AFSortOrder.Ascending, 100);

                Logger.Info($"{log}User: {user.Name}, ncts.Count:{ncts.Count}, IsDirty: {user.IsDirty}, IsNew:{user.IsNew}, IsDefinedByActiveDirectory:{user.IsDefinedByActiveDirectory}, Security:{user.Security}");

                           foreach (AFNotificationContactTemplate template in ncts)

                {

                    Logger.Info($"{log} EndPointName: {template.Name}, {template.ConfigString}");

                }

            }

 

Example Output

Total contacts count: 4112

Count after considering only contacts of type user: 1013

User: Pehr Evind, ncts.Count:1, IsDirty: False, IsNew:False, IsDefinedByActiveDirectory:True, Security:Read

   EndPointName: Pehr Evind _Email, 

User: Juho Kusti, ncts.Count:0, IsDirty: False, IsNew:False, IsDefinedByActiveDirectory:True, Security:Read

User: Lauri Ingman, ncts.Count:1, IsDirty: False, IsNew:False, IsDefinedByActiveDirectory:True, Security:Read

     EndPointName: Lauri Ingman - Email,

 

Then I go to AF Explorer and search for the contact “Juho Kusti”, then I actually see that contact exists and under the contact there exists end point “Juho Kusti - Email”. That’s all I did in AF, and when I try to exit AF Explorer, I get a message saying there are changes made. If I click on Check in button then I see that contact is edited actually. I press “Undo checkout” and then run the same code again and now the code finds the email end point for “Juha Kusti - Email”

 

User Juho Kusti, ncts.Count:1, IsDirty: False, IsNew:False, IsDefinedByActiveDirectory:True, Security:Read

   EndPointName: Juho Kusti - Email, 

 

Actual problem is:

There is custom AF SDK code that gets invoked when user tries to subscriber for the notification. At that point, search is made to find the email end point using above pasted code. As the email end point is not found, the code creates new email end point. This is resulting to duplicate email end points as AF Explorer contact search will then show two email end points. 

Is there any refresh issue and know how to overcome through AF SDK? How come AF Explorer is able to find it while the above piece of code is not able to find it?

 

Few side questions:

Some contact email end points end with “_Email” and some end with “ – Email”, know from where this difference come from? Is it coming as we moved on to different AF Versions?

After creating AD user account, anything special to be done to get AF Contact created? and to get email end point created under AF Contact?

 

Note:  Tried  AFNotificationContactTemplateSearch() instead of AFNotificationContactTemplate.FindNotificationContactTemplatesByContact() and it’s the same result.

 

Outcomes