Update field with value which is adding in related list

Nisha Mishra23
Tera Contributor

There is custom field on sys_user table u_skill which is used to display skills. There is related list under user table which sys_user_has_skill . I trying to add the skill from related list and want that to display in u_skill field but I am getting the result.

(function executeRule(current, previous /*null when async*/) {

    gs.info("Business Rule Triggered for User: " + current.user); // Log the user ID to check if the rule is triggered

    // Get the user record associated with the skill
    var user = current.user;

    // Get all the skills related to this user
    var skills = new GlideRecord('sys_user_has_skill');
    skills.addQuery('user', user);
    skills.query();

    var userSkills = [];

    // Loop through the skills and store them in an array
    while (skills.next()) {
        if (skills.skill) {
            userSkills.push(skills.skill.name);  // Collect all skill names
            gs.info("Skill: " + skills.skill.name);  // Log each skill name
        } else {
            gs.info("No skill found for this record.");
        }
    }

    // If userSkills array has any skills, update the u_skill field
    if (userSkills.length > 0) {
        // Join skills into a single string, separated by commas
        var skillsString = userSkills.join(', ');  
       
        // Log the final string before updating
        gs.info("Skills String to be updated: " + skillsString);

        // Update the sys_user record
        var userRecord = new GlideRecord('sys_user');
        if (userRecord.get(user)) {
            userRecord.u_skill = skillsString;  // Update the u_skill field with the concatenated skills
            userRecord.update();  // Save the changes
            gs.info("User skills updated: " + userRecord.u_skill);  // Log the updated skills
        } else {
            gs.error("User record not found for ID: " + user);
        }
    } else {
        gs.info("No skills found to update for user: " + user);
    }

})(current, previous);
3 REPLIES 3

Laveena-Agarwal
Kilo Sage

Hi @Nisha Mishra23 

 

I’ve implemented the same script for your use case in my PDI, and it’s working as expected.

Please ensure the Business Rule is configured to run "After" "Insert" on the sys_user_has_skill table.
This script will not work if it runs in Before.

Yes I am using after but the all the skills are not visible on field 

@Nisha Mishra23 

You’re right—this happened to me as well.

I found that the string field length was insufficient, which is why all skills weren’t updating. After increasing the length to 1000, it worked as expected: all 8 skills are now updated in the skill field and are correctly reflected in the related list -

 

 

Screenshot 2026-01-14 at 4.00.03 PM.pngScreenshot 2026-01-14 at 3.58.45 PM.png