Author Topic: skills assigned  (Read 2577 times)

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
skills assigned
« on: November 03, 2017, 09:18:08 AM »
Hello,

does someone know how I can see which skill is assigned?
In person I have not really a link to skills only to skill level but that does not help me further.

Any help would be helpful.

Offline PeteHoyle

  • Full Member
  • ***
  • Posts: 126
  • Karma: 13
Re: skills assigned
« Reply #1 on: November 03, 2017, 10:04:00 AM »
Hi,

I'm guessing your are using the PSDK CommApp block, if please see the code sample below:

                [code]     
                CfgPersonQuery q = new CfgPersonQuery();
                q.UserName = "Monique";

                CfgPerson person = confService.RetrieveObject<CfgPerson>(q);

                foreach (CfgSkillLevel level in person.AgentInfo.SkillLevels)
                {
                    String skill_name = level.Skill.Name;
                    log.Debug("SkillName: " + skill_name + " Value: " + level.Level);
                }[/code]

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: skills assigned
« Reply #2 on: November 03, 2017, 01:11:44 PM »
super thank you a lot

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: skills assigned
« Reply #3 on: November 09, 2017, 09:19:31 AM »
Im now trying to remove some skills and skill is also removed but I get exception

collection was modified enumeration operation may not execute

Does someone know this exception and what is causing this?

[code][/foreach (CfgSkillLevel level in person.AgentInfo.SkillLevels)
                {
                   
                    if (level.Skill.Name == "TEST")
                    {
                        person.AgentInfo.SkillLevels.Remove(level);
                       
                       
                    }
                }
person.Save();code][/code]

Offline PeteHoyle

  • Full Member
  • ***
  • Posts: 126
  • Karma: 13
Re: skills assigned
« Reply #4 on: November 16, 2017, 07:38:51 PM »
It's a standard error because you are trying to remove an object from a collection you are iterating.

[url=https://stackoverflow.com/questions/6177697/c-sharp-collection-was-modified-enumeration-operation-may-not-execute]https://stackoverflow.com/questions/6177697/c-sharp-collection-was-modified-enumeration-operation-may-not-execute[/url]

You need to do something like this instead:

[code]        CfgSkillLevel skillToRemove = null;
        foreach (CfgSkillLevel level in person.AgentInfo.SkillLevels)
        {
            if (level.Skill.Name == "MySkill")
            {
                skillToRemove = level;
                break;
            }
        }

        if (skillToRemove != null)
        {
            person.AgentInfo.SkillLevels.Remove(skillToRemove);
            person.Save();
        }[/code]