Searching for users with multiple skills

kcouvillon
Tera Contributor

I have an interesting question. I am building a front end portal page that allows portal users to search for users with skills. I got how to handle if a user has one skill, but what about multiple? Lets just say you want to find someone who codes in Python AND Java, how would you be able to search the search the "sys_user_has_skill" table to return records where a user has both skills "Python" and "Java", and with one gliderecord/glideaggregate call (for repeatability). I know you can do that with tags, but not sure with skills.

 

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

HI @kcouvillon ,
I trust you are doing great.
Here is an example of how this could be implemented:

// Function to find users with both Python and Java skills
function findUsersWithBothSkills() {
    var pythonUsers = getUsersWithSkill('Python');
    var javaUsers = getUsersWithSkill('Java');

    // Find users who are in both lists
    var usersWithBothSkills = [];
    for (var i = 0; i < pythonUsers.length; i++) {
        if (javaUsers.indexOf(pythonUsers[i]) > -1) {
            usersWithBothSkills.push(pythonUsers[i]);
        }
    }

    return usersWithBothSkills;
}

// Function to get user IDs for a given skill
function getUsersWithSkill(skillName) {
    var userIDs = [];
    var gr = new GlideRecord('sys_user_has_skill');
    gr.addQuery('skill.name', skillName);
    gr.query();

    while (gr.next()) {
        userIDs.push(gr.user.toString());
    }

    return userIDs;
}

var users = findUsersWithBothSkills();
gs.info('Users with both Python and Java skills: ' + users.join(', '));

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

6 REPLIES 6

That is close to what I was thinking for an alternative to what I am looking for. I was hoping to find a way to do it with one glide call so we do not have to query all users and all tags (which will eventually get very large), plus I can just retrieve the specific subsets of the results that I need with results with chooseWindow to make it less resource intensive. 

That should work!