The reason is probably the following: the if
Q[Role=..] statement uses the function BAPI_USER_GET_DETAIL in order to read the
user roles. This works only if the RFC user is allowed to access the user master
record, which depends on the user group stored in this master record. So it can
work for some users in some systems, but not for others. Please grant the right
authorization to the RFC user, as described in our documentation menu item
"RFC" (first menu); it then will work for all targeted users.