Wednesday, February 16, 2011

InfoPath - Inserting line breaks into text using Rules

Create a new XML file 'linebreak.xml' and save it.

<?xml version="1.0" encoding="UTF-8"?>

Then in InfoPath go to Tools | Data Connections and click Add. Select Receive data, then XML Document. Browse to characters.xml then complete the wizard. When it asks “The selected file is not part of the form...add this file...?” click Yes. At this point we’ve just added a resource file to the template that gets loaded into a declaratively-accessible DOM - no code required.

Testing it:

Add a Button control, open up the properties and click Rules. Add a Rule, and add an Action of the type “Set a field’s value”. For the field pick the text box’s field (e.g. field1). For the new value, use the formula builder and build the following expression:
concat(field1, @crlf, "Hello, World!")
Result would look like:

Hello, World!


No comments: