Update list script
						
					
					
				
			
		
	
			
	
	
	
	
	
			
		
			
	
	
			
				
		
		
			Community Alums
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		
	
		
	
	
				
		
	
		
	
	
			Not applicable
		
	
				
		
			
					Options
			
				
					
	
			
		
	- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-03-2023 08:11 AM
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
	
		
		
			
			
			
					
	
			Options
			
				
					
	
			
		
	- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-03-2023 08:26 AM
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
Options
			
				
					
	
			
		
	- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-03-2023 08:44 AM
Hi, thanks for coming back me... No joy with that one still not working.
Any other ideas?
