Hello everybody,
I would like to share my solution which took quite some time to find. Maybe it can help somebody.
Recently I needed a workflow that extracts the contents of .eml-email files in a library. As the mailcontent was base64-encoded and no out-of-the-box solution was provided by the workflow designer, I had to come up with something. Writing a custom inline function would be obvious but because then a .wsp has to be deployed which causes an IIS-restart which needed to be announced and scheduled due to company-processes. So this was no short term option for me. Also using an external webservice was a no-go as of data protection reasons.
So finally I found a solution which includes the SQL Server SharePoint uses. In this way I don't leave the SharePoint-environment and don't have to deploy anything.
The only thing necessary is that I had to ask my infrastructure collegues to create a new native sql account which gets the server role 'public' only to prevent any abuse.
Then I created an UDA which contains a single "Execute SQL"-Action that executes a SQL query that does the base64-decoding. The UDA needs two parameter, one input for the base64 encoded text, one output for the result.
After a lot of googleing I found a SQL query that fits the requirement but also cares for encoding for other language than just english (non-ascii characters) like used in french, german, swedish, etc. With a little adjustment and the use of the input-parameter, the query looks like this:
SELECT CONVERT(NVARCHAR(MAX), CONVERT(XML, '<?xml version="1.0" encoding="UTF-8"?><![CDATA[' + CONVERT(VARCHAR(MAX), CONVERT(XML, N'{WorkflowVariable:mtxtBase64EncodedText}') .value('.','varbinary(max)') ) + ']]>' ) );
With having this capsuled in an user defined action, every workflow designer can use this functionality without the need to care for sql-connections or knowledge about SQL language.