Genesys CTI User Forum

Genesys CTI User Forum => Genesys-related Development => Topic started by: carpio on September 29, 2017, 07:37:56 AM

Title: PSDK Add\Remove AgentLogin from Person
Post by: carpio 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
Title: Re: PSDK Add\Remove AgentLogin from Person
Post by: PeteHoyle 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]
Title: Re: PSDK Add\Remove AgentLogin from Person
Post by: carpio 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();

Title: Re: PSDK Add\Remove AgentLogin from Person
Post by: PeteHoyle 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]
Title: Re: PSDK Add\Remove AgentLogin from Person
Post by: carpio 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