Created
April 15, 2024 09:48
-
-
Save Ray901/33797d1bc43671d535839fc3b62e2696 to your computer and use it in GitHub Desktop.
Use R to get Tableau RLS User Filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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