Crimson3708
(Alexander Hatcher)
August 23, 2023, 2:10pm
1
This was originally a discussion here:
Hi folks,
I’m attempting to learn more about beanshell’s functionalities and there doesn’t seem to be any examples that I can find for delimited file manipulation specifically calling out for the removal of the domain name in one of the columns.
Hoping you guys can help me with figuring this out.
I get the following error
sailpoint.connector.ConnectorException: BeanShell script error: Sourced file: inline evaluation of: ``import sailpoint.connector.DelimitedFileConnector; Map map = Delimited…
The problem is that one of the columns has the username formatted as DOMAIN\username - so in order to correlate I made a simple buildmap to remove the DOMAIN\ portion.
The catch is it doesn’t seem like Beanshell is properly processing the escaped \ and just getting mucked up somehow.
Un-escaped script
import sailpoint.connector.DelimitedFileConnector;
Map map = DelimitedFileConnector.defaultBuildMap( cols, record );
String columnUsername = (String) map.get( "Table0_Details3" );
columnUsername = columnUsername.replaceAll("DOMAIN\", "");
map.put("Table0_Details3",columnUsername);
return map;
Escaped Script
import sailpoint.connector.DelimitedFileConnector;\r\n\r\n Map map = DelimitedFileConnector.defaultBuildMap( cols, record );\r\n String columnUsername = (String) map.get( \"Table0_Details3\" );\r\n columnUsername = columnUsername.replaceAll(\"DOMAIN\\\", \"\");\r\n map.put(\"Table0_Details3\",columnUsername);\r\n return map;
Crimson3708
(Alexander Hatcher)
August 23, 2023, 7:17pm
2
This issue was resolved by the amazing Nithesh Rao in this post - BeanShell - BuildMap Replace Word - #10 by iam_nithesh
His summary was excellent in pointing out this was an age old issue with how Java handles the data.
columnUsername = columnUsername.replace("Domain\\", "");
Try this?
The reason I am asking is because in java replace and replaceAll methods handle the searchFor
string differently. While replace method treats it as a character squence, replaceAll treats it as regex. This is an age old issue with Java and while using replaceAll method you will have to use \\\\
to escape a single \
as internally these are compiled by Java and then by regex. If you use replace then it is just compiled by Java and \\
will be treated a \
This was my finished code escaped
import sailpoint.connector.DelimitedFileConnector;\r\n\r\n Map map = DelimitedFileConnector.defaultBuildMap( cols, record );\r\n String columnUsername = (String) map.get( \"Table0_Details3\" );\r\n columnUsername = columnUsername.replace(\"DOMAIN\\\\\", \"\");\r\n map.put(\"Table0_Details3\",columnUsername);\r\n return map;
1 Like