Skip to content

Instantly share code, notes, and snippets.

@Ray901
Created April 15, 2024 09:48
Show Gist options
  • Select an option

  • Save Ray901/33797d1bc43671d535839fc3b62e2696 to your computer and use it in GitHub Desktop.

Select an option

Save Ray901/33797d1bc43671d535839fc3b62e2696 to your computer and use it in GitHub Desktop.
Use R to get Tableau RLS User Filter
rm(list=ls())
library(xml2)
xml_Doc <- read_xml("tableau.twb")
xml_groupfilter <- xml_find_all(xml_Doc, ".//group[@name='[FilterA]']//groupfilter[@function='filter']")
userList <- lapply(xml_groupfilter,function(x){
tmpUser <- xml_attr(x,"expression")
tmpUser <- gsub('ISCURRENTUSER[(]|[)]','',tmpUser)
if (grepl('a-data.com',tmpUser)) {
tmpLevelXml <- xml_find_all(x,".//groupfilter[@function='member'][@level='[ColumnA]']")
if (length(tmpLevelXml)>0) {
tmpLevel <- gsub('["\""]','',xml_attr(tmpLevelXml,"member"))
tmpDat <- data.frame(
BIUser = tmpUser,
UserFilter = 'FilterA',
LevelCol = 'ColumnA',
LevelValue = tmpLevel,
stringsAsFactors = F
)
} else {
tmpDat <- NULL
}
} else {
tmpDat <- NULL
}
return(tmpDat)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment