Monday, April 27, 2015

Eliminate Trailing Spaces from Fields with KingswaySoft

From time to time you end up with field values that contain trailing spaces. Typically when creating records through the UI or importing from Excel values should be trimmed of any extraneous spaces. When creating and updating records using the SDK this same logic isn’t applied. Normally most people wouldn’t even notice extra spaces being appended to a field value but in cases when you’re working with the data, maybe in some sort of integration these extra spaces can become an issue. One example that comes to mind that I ran across was a customer was trying to import data that had a reference to a lookup field. Instead of using the GUID value they were using the text value. Normally this should would just fine but in this instance it didn’t. I’m not sure exactly how the original data was created but all the values on the reference fields contained extra trailing spaces so when CRM went to do a lookup against the fields it failed because it was not an exact match.

2015-04-26_23-26-25

If you have just a handful of fields it’s easy enough just to open the records and delete the extra spaces and re-save. When you run into scenarios with larger amounts of records that option isn’t so appealing. A slightly less painful method is to export the offending records to Excel, use some Excel wizardry to remove the spaces and the re-import. This approach is a bit of a pain because it’s a lot of steps and forces you to export all records because you aren’t able to directly (to my knowledge at least) do an advanced find in CRM for data where you query parameter is only a space – “Ends With <space>”

KingswaySoft to the Rescue


We still can’t do an advanced find for fields that end with a space from CRM but we can through a FetchXML query in the KingswaySoft SSIS adapter. So to get a jumpstart, in CRM do an advanced find for you field and substitute any letter for the “Ends With” condition and then view the resulting FetchXML. Now all you need to do is change the letter you picked to a space.

2015-04-26_23-31-11

In the CRM Source use the updated FetchXML.

2015-04-26_23-33-33

Next add a Derived Column Transformation. Take the existing field and use the “TRIM” function to remove the extra spaces.

2015-04-26_23-35-06

On your CRM Destination, map the entity id and the updated value back to the original property.

2015-04-26_23-36-20

And that’s it! Run the job and only records where the specified fields ending with spaces will get updated.

Special thanks to the folks over at KingswaySoft for naming me an MVP recently!