Val() not working - what I'm doing wrong?

Why this val() is not working? It’s not updating the username.
When I type string instead of val(newusername) it works.
user_id 4 have a username set.

upsert {
 query {
checkNameNew(func: eq(user_id, "4")) {
      newusername as username
}	
  
userB as var(func: eq(user_id, "6"))

}

mutation {
	set {
			uid(userB) <username> val(newusername) .
	}
}

}

I got a solution a couple of threads below.

upsert {
 query {
checkNameNew(func: eq(user_id, "4")) {
      newusername as username
}	

 qName(){
        nu as max(val(newusername))
      }
  
userB as var(func: eq(user_id, "6"))

}

mutation {
	set {
			uid(userB) <username> val(nu) .
	}
}

}

be careful with this. It will work in a 1 to 1 manner. If you try one to many, it will messup with your values.

Thanks for warning. In my case every unique user id should return the same value (username) and it should be safe in this case.