Update list script

Andrew_TND
Mega Sage
Mega Sage

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
Tera Sage

Hi @Andrew_TND ,

 

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

 

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

Any other ideas?