How to upload multiple skills into ServiceNow employee profile table

Siva vittanala
Tera Contributor

Hi team, I wanted to load data into servicenow Employee profile table from Excel sheet using import set and transform map process.

But in Excel user skill column contains multiple skills, but in the system it will table one record each time. how to split the data having multiple skills and load into service now tables.

 


I have Excel sheet and ServiceNow profile table

IDNameManagerUser RoleUser Skill

 123456    Testuser                                                      testmanager                     developer                                     java,.net

 

Sivavittanala_1-1747821783233.png

 

I want to upload above format skill data into primary resource skill field. this field is refer to cmn_skill table.

1 ACCEPTED SOLUTION

Hello @Siva vittanala ,

 

So you have added this as an onAfter Transform Script on the Transform Map that has "Employee Profile" as the target table, correct?

 

If so then you need to change the line that assigns the "userId" value, because "target" is the Employee Profile record and the user is referenced in its "user" field:

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    var skillNames = source.getValue('u_user_skill').split(',');
    var userId = target.getValue('user');

    skillNames.forEach(skillName => {
        var gr = new GlideRecord('sys_user_has_skill');
        gr.addQuery('user', userId);
        gr.addQuery('skill.name', skillName);
        gr.query();
        if (gr.hasNext()) return;
        gr.initialize();
        gr.setValue('user', userId);
        gr.setDisplayValue('skill', skillName);
        gr.insert();
    });

})(source, map, log, target);

 

Your script was assigning the sys_id of the Employee Profile to "userId", which resulted in the issue.

 

Regards,

Robert

 

View solution in original post

8 REPLIES 8

We can create multiple records for each skill. Like for one user multiple records.

Hello @Siva vittanala ,

 

Which records are you referring to?

Employee Profiles? No, it's not possible to create multiple profiles for the same user:

RobertH_0-1747828169207.png

 

Or are you talking about User Skills [sys_user_has_skill]? That's the solution I was talking about in my previous response already. So I'm not sure what you're trying to say.

 

Regards,

Robert

 

I have to update the skills on sys_user_has_skill table i am using this below script 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {


    var skillNames = source.getValue('u_user_skill').split(',');
   // var userId = target.user.sys_id;
   var userId = target.getUniqueValue();
   gs.log(userId +'siva12345');


    skillNames.forEach(skillName => {
        var gr = new GlideRecord('sys_user_has_skill');
        gr.addQuery('user', userId);
        gr.addQuery('skill.name', skillName);
        gr.query();
        if (gr.hasNext()) return;
        gr.initialize();
        gr.setValue('user', userId);
        gr.setDisplayValue('skill', skillName);
        gr.insert();
    });
   


})(source, map, log, target);


but only employee profile table fields was getting updated not in s
ys_user_has_skill table

Hello @Siva vittanala ,

 

So you have added this as an onAfter Transform Script on the Transform Map that has "Employee Profile" as the target table, correct?

 

If so then you need to change the line that assigns the "userId" value, because "target" is the Employee Profile record and the user is referenced in its "user" field:

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    var skillNames = source.getValue('u_user_skill').split(',');
    var userId = target.getValue('user');

    skillNames.forEach(skillName => {
        var gr = new GlideRecord('sys_user_has_skill');
        gr.addQuery('user', userId);
        gr.addQuery('skill.name', skillName);
        gr.query();
        if (gr.hasNext()) return;
        gr.initialize();
        gr.setValue('user', userId);
        gr.setDisplayValue('skill', skillName);
        gr.insert();
    });

})(source, map, log, target);

 

Your script was assigning the sys_id of the Employee Profile to "userId", which resulted in the issue.

 

Regards,

Robert