Skip to Main Content

General Development Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Update User Variables for multiple users

1975931Sep 18 2024

I was working on a groovy script to update all the user variables at once without setting those from the ‘User Preferences’. The code worked for the only user who triggered the rule; i.e. the user variable was updated for admin only if the admin triggered the rule, while for the rest of the users, the variables were not updated. Can anyone give any input/suggestion on how to fix the code to make it work for all the users, i.e. if admin triggers the rule, the variables should be updated for all the users and not the admin only.

Below is the code:

//Initial setup of User Variables
//Created: Sep

String userName = operation.user.getName(); //get username for logged in user
println userName

/*** Set user variables based on username or default ****/
Map userVarMap = [
1: [username:'default',
'Years-PMYear':'FY21',
'Period-Month':'Sep',
],
]

String userVarString = userVarMap.find { it.value.username == userName }?.value // find a single entry for logged in user
if (userVarString == null) {
userVarString = userVarMap.find { it.value.username == 'default' }?.value // find default entry if user not found
}

println "User Variables for $userVarString"

Map userMap=[:]
userMap += userVarString.replaceAll('\\{|\\}', '').split(',').collectEntries { entry ->
def pair = entry.split('=')
[(pair.first().trim()): pair.last().trim()]
} // convert userVarString entry back to Map object type

for (i in userMap) {
if(i.key == 'username')
continue
String mapKey = i.key.toString()
def dimPair = mapKey.split('-')
def dimName = dimPair.first().trim()
def userVar = dimPair.last().trim()
String userVarValue = i.value.toString()

Dimension appDim = operation.application.getDimension(dimName)
UserVariable appUserVar = operation.application.getUserVariable(userVar)
Member appUserVarMember = appDim.getMember(userVarValue)
String status = operation.application.setUserVariableValue(appUserVar,appUserVarMember)

println "User Variable set as Dimension: $dimName, User Variable: $userVar, User Variable Value: $userVarValue"
}

Comments
Post Details
Added on Sep 18 2024
0 comments
29 views