Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Update list script

Community Alums
Not applicable

Hi everyone,

I've added a script to run on a business rule which pushes the required_persona from the request to the user profile which adds it to an existing list field called u_software. However cant seem to get it to work.

Any suggestions where I'm going wrong?

 

(function executeRule(current, previous /*null when async*/ ) {
    var persona = current.variables.required_persona.getDisplayValue().split(',');
	
    var user = new GlideRecord("sys_user");
    user.addQuery("sys_id", current.requested_for.getDisplayValue());
    user.query();
	
    if (user.next()) {
        var userPersona = user.u_software.toString().split(',');
        persona.forEach(function(item) {
            if (userPersona.indexOf(item) == -1) {
                userPersona.push(item);
            }
        });
        user.u_software = userPersona.join(',');
    }
})(current, previous);


 

2 REPLIES 2

Danish Bhairag2
Tera Sage

Hi @Community Alums ,

 

Can you try the below code :

 

(function executeRule(current, previous /*null when async*/ ) {
    var persona = current.variables.required_persona.getDisplayValue().split(',');
	
    var user = new GlideRecord("sys_user");
    user.addQuery("sys_id", current.requested_for); // here as u r trying to match sys id u should not write getDisplayValue
    user.query();
	
    if (user.next()) {
        var userPersona = user.u_software.toString().split(',');
        persona.forEach(function(item) {
            if (userPersona.indexOf(item) == -1) {
                userPersona.push(item);
            }
        });
        user.u_software = userPersona.join(',');
    }
})(current, previous);

 

Thanks,

Danish

 

Community Alums
Not applicable

Hi, thanks for coming back me... No joy with that one still not working.

Any other ideas?