Author Topic: PSDK Add\Remove AgentLogin from Person  (Read 2785 times)

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
PSDK Add\Remove AgentLogin from Person
« on: September 29, 2017, 07:37:56 AM »
Hello,

here I'am again :)

I want to add or remove a AgentLogin to a person but do get an error when running this code:

var login = func.agentlogin_query("1234").SingleOrDefault();
            var person = func.person_query(login.DBID).SingleOrDefault();
                     

            CfgAgentLoginInfo info = new CfgAgentLoginInfo(service,person);
            info.SetAgentLoginDBID(login.DBID);
            Console.WriteLine(info.ToString());
            person.AgentInfo.AgentLogins.Add(info);
            person.Save();


I get this error:

{"Object reference not set to an instance of an object."}


The extension exists and the console write is giving me this result:

CfgObject type = Genesyslab.Platform.ApplicationBlocks.ConfigurationObjectModel.CfgObjects.CfgAgentLoginInfo
properties :
{
    agentLoginDBID : 111
}

Can anyone help?
What I'm doing wrong?

Thanks
« Last Edit: September 29, 2017, 07:40:17 AM by carpio »

Offline PeteHoyle

  • Full Member
  • ***
  • Posts: 126
  • Karma: 13
Re: PSDK Add\Remove AgentLogin from Person
« Reply #1 on: September 29, 2017, 09:29:03 AM »
For me that worked.

Below is the modified slightly to retrieve the CfgAgentLogin and use that when creating the CfgAgentLoginInfo object, but even using your way of using .SetAgentLoginDBID worked.



[code]                    CfgPersonQuery qPerson = new CfgPersonQuery();
                    qPerson.UserName = "phoyle";

                    CfgPerson myPerson = confService.RetrieveObject<CfgPerson>(qPerson);

                    if (myPerson == null)
                    {
                        log.Info("Person Not Valid");
                        return;
                    }

                    CfgAgentLoginQuery qLogin = new CfgAgentLoginQuery();
                    qLogin.Dbid = 422;
                    CfgAgentLogin myLogin = confService.RetrieveObject<CfgAgentLogin>(qLogin);

                    if (myLogin == null)
                    {
                        log.Info("AgentLogin Not Valid");
                        return;
                    }

                    CfgAgentLoginInfo agentInfo = new CfgAgentLoginInfo(confService, myPerson);
                    //agentInfo.SetAgentLoginDBID(422);
                    agentInfo.AgentLogin = myLogin;
                    myPerson.AgentInfo.AgentLogins.Add(agentInfo);
                    myPerson.Save();[/code]

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: PSDK Add\Remove AgentLogin from Person
« Reply #2 on: September 29, 2017, 10:19:40 AM »
I saw my mistake when adding the number, I have searched for the agent who got the agentlogin assigned.
so adding is now woking aswell.

Just removing is still not working:

var login = func.agentlogin_query("1324").SingleOrDefault();
            var person = func.person_query(login.DBID).SingleOrDefault();


            CfgAgentLoginInfo info = new CfgAgentLoginInfo(func.app_service, person);
            info.SetAgentLoginDBID(login.DBID);
            Console.WriteLine(info.ToString());
            person.AgentInfo.AgentLogins.Remove(info);
            person.Save();


Offline PeteHoyle

  • Full Member
  • ***
  • Posts: 126
  • Karma: 13
Re: PSDK Add\Remove AgentLogin from Person
« Reply #3 on: September 29, 2017, 12:39:58 PM »
You could make a method based on this code to remove the Agent Login:

[code]

                    CfgPersonQuery qPerson = new CfgPersonQuery();
                    qPerson.UserName = "phoyle";

                    CfgPerson myPerson = confService.RetrieveObject<CfgPerson>(qPerson);
                   
                   
                    if (myPerson == null)
                    {
                        log.Info("Person Not Valid");
                        return;
                    }

                    CfgAgentLoginInfo loginToRemove = null;
                    foreach (CfgAgentLoginInfo loginInfo in myPerson.AgentInfo.AgentLogins)
                    {
                        if (loginInfo.AgentLogin.LoginCode == "0001")
                        {
                            loginToRemove = loginInfo;
                        }
                    }

                    if (loginToRemove != null)
                    {
                        myPerson.AgentInfo.AgentLogins.Remove(loginToRemove);
                        myPerson.Save();
                    }                 

[/code]

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: PSDK Add\Remove AgentLogin from Person
« Reply #4 on: October 02, 2017, 12:54:07 PM »
Thanks PeteHoyle, with you code its working fine.
I have to modify it a bit but for now its working.

Big Thanks