Author Topic: skills assigned  (Read 978 times)

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
skills assigned
« on: November 03, 2017, 06:18:08 PM »
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: 106
  • Karma: 9
Re: skills assigned
« Reply #1 on: November 03, 2017, 07:04:00 PM »
Hi,

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

               
Code: [Select]
     
                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);
                }

Offline carpio

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

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: skills assigned
« Reply #3 on: November 09, 2017, 06:19:31 PM »
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: [Select]
[/foreach (CfgSkillLevel level in person.AgentInfo.SkillLevels)
                {
                   
                    if (level.Skill.Name == "TEST")
                    {
                        person.AgentInfo.SkillLevels.Remove(level);
                       
                       
                    }
                }
person.Save();code]

Offline PeteHoyle

  • Full Member
  • ***
  • Posts: 106
  • Karma: 9
Re: skills assigned
« Reply #4 on: November 17, 2017, 04:38:51 AM »
It's a standard error because you are trying to remove an object from a collection you are iterating.

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

You need to do something like this instead:

Code: [Select]
        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();
        }