BeanShell - BuildMap Replace Word

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 = DelimitedFile . . . '' Token Parsing Error: Lexical error at line 5, column 60. Encountered: "\r" (13), after : "\");": <at unknown location> BSF info: CRM Partner Services BuildMap Modifier at line: 0 column: columnNo

The un-escaped code

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;

Hello @Crimson3708 hope all is good.

Is this the complete BuildMap rule?

Right now it appears the extra \ may be throwing it off in beanshell and causing the error we witness, did you try with just the one backslash i.e

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;

As a reference : BuildMap Rule | SailPoint Developer Community

Am I correct in assuming your using essentially the msDS-principalName format in your CSV file and that the record value would always be in format DOMAIN\crimson3708 or would it in fact be DOMAIN\crimson3708

Kind Regards,
Omar

Good morning!

Hmm I believe it to be a complete buildmap - I’ve done small similar ones like this in the past. This is a little bit outside what I’m used to since I’ve never replaced/gotten rid of a portion of a cell via buildmap.

The extra \ there was actually so VS Code would show the correct parsing of java as it would shout at me about non escaped backslash haha.

This is the escaped code - the domain is actually a placeholder sanitized to not show the actual domain.

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;

I tested further with this and looks like I got the same error.

sailpoint.connector.ConnectorException: BeanShell script error: Sourced file: inline evaluation of: ``import sailpoint.connector.DelimitedFileConnector; Map map = DelimitedFile . . . ‘’ Token Parsing Error: Lexical error at line 5, column 60. Encountered: “\r” (13), after : “");”: BSF info: CRM Partner Services BuildMap Modifier at line: 0 column: columnNo

The main goal with this was to get rid of the DOMAIN\ that shows in the user listing because we can’t correlate off that. (We also only have like 10 or so extension attributes to go off of for searchable fields)

Good day @Crimson3708 I did also try the same for us and also tried a few different approaches too, it seems like there is an issue with the escaping of the forward slash in beanshell rule import causing the rule to go awry. This may be a bug in escaping the forward slash causing this simple rule to go awry, hope to feed back soon.

Should I submit a bug report with SailPoint?

Hey Alexander, yes if it’s not a blocker, would you be so kind to mention this here please:

if not engaging SailPoint support would be the next best route :

you can either follow above process which may be easier or email : [email protected] with the details on the issue and the updates will follow.

Please note: I have additionally raised this issue internally but no response as of yet.

Can you please try

columnUsername = columnUsername.replaceAll("Domain\\\\", "");

and share the outcome?

I attempted to modify it - it errored on saving the change via the IDN Visual Studio Code Extension - it looks like its blocking cause it things its not escaped properly.

Failed to save ‘CRM App BuildMap Modifier’: Unable to write file ‘idn://domain-sb.identitynow.com/beta/connector-rules/Unique ID/CRM App BuildMap Modifier’ (Error: The request could not be parsed.)

Worth noting that the quoting tools on this site seems to be getting rid of backslashes depending on what quote style I use.

The username is actually formatted DOMAIN\ un-escaped, and DOMAIN\\\ escaped.

This is the script which I think should preserve the escapes I have in there.

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;
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 \

2 Likes

Wow! Thanks Nithesh - this resolved it.

I switched the line as you instructed - escaped it, which shows like this - and it finally worked! :piñata: :tada:

This is what my code looks like escaped if anyone else needs to see the example that worked for me.

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

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.