Link to home
Start Free TrialLog in
Avatar of steam23
steam23Flag for Canada

asked on

Change a plain text field into a Rich Text field without loosing data

I call it the Ikea moment. It's when you are almost done building and you realize that you've put something in backwards, and as a result you're going to have to redo the entire thing.

I seem to have an ikea moment with my infopath form. I had to update a template that our students use for doing writing activities.  There was a problem with content types on the sharepoint folder in which they are stored, so it seemed like the easiest way to do it would be to start from scratch. Unfortunately, when I tried to link the new template to the old files, none of the data showed up.

I had just finished spending the last two days recreating all the forms in the new template when I realized that one of the fields was set as text(string) or plaintext, when it should have been rich text. Doh!

I did a little searching and found that the way to accomplish this would be to edit the myschema.xsd file, but i can't seem to get it to work properly. I'm hoping that someone who knows xml better than me can help out here.

The post I found, (here: http://www.omgili.com/newsgroups/microsoft/public/infopath/5597EE8D-24D9-467B-A52D-B535D686B59Dmicrosoftcom.html&q=rich+text) suggests changing the xsd:element tag for the field in question. In my form, however; the "Work" field is only referenced as xsd:attribute, (possibly because it's a part of a repeating table) which won't accept the rich text complex type i copied from a test file.
            <xsd:complexType mixed="true">
                  <xsd:sequence>
                        <xsd:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/1999/xhtml" processContents="lax"/>
                  </xsd:sequence>
            </xsd:complexType>

Any help would be appreciated. I really don't want to have to go back again and redo all the forms in that folder.

Thanks!
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema targetNamespace="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-10-27T17:45:48" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-10-27T17:45:48" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<xsd:attribute name="Number" type="xsd:string"/>
	<xsd:attribute name="Work" type="xsd:string"/>
	<xsd:element name="myFields">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="my:StudentName" minOccurs="0"/>
				<xsd:element ref="my:Date" minOccurs="0"/>
				<xsd:element ref="my:Program" minOccurs="0"/>
				<xsd:element ref="my:LessonNumber" minOccurs="0"/>
				<xsd:element ref="my:Exercise" minOccurs="0" maxOccurs="unbounded"/>
			</xsd:sequence>
			<xsd:anyAttribute processContents="lax" namespace="http://www.w3.org/XML/1998/namespace"/>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="StudentName" type="my:requiredString"/>
	<xsd:element name="Date" type="xsd:date"/>
	<xsd:element name="Program" type="xsd:string"/>
	<xsd:element name="LessonNumber" type="xsd:string"/>
	<xsd:element name="Exercise">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="my:Part" minOccurs="0"/>
				<xsd:element ref="my:Item" minOccurs="0" maxOccurs="unbounded"/>
				<xsd:element ref="my:Checkboxes" minOccurs="0"/>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="Part" type="xsd:string"/>
	<xsd:element name="Item">
		<xsd:complexType>
			<xsd:sequence/>
			<xsd:attribute ref="my:Number"/>
			<xsd:attribute ref="my:Work"/>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="Checkboxes">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="my:Checkbox1" minOccurs="0"/>
				<xsd:element ref="my:Checkbox2" minOccurs="0"/>
				<xsd:element ref="my:Checkbox3" minOccurs="0"/>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="Checkbox1" nillable="true" type="xsd:boolean"/>
	<xsd:element name="Checkbox2" nillable="true" type="xsd:boolean"/>
	<xsd:element name="Checkbox3" nillable="true" type="xsd:boolean"/>
	<xsd:simpleType name="requiredString">
		<xsd:restriction base="xsd:string">
			<xsd:minLength value="1"/>
		</xsd:restriction>
	</xsd:simpleType>
	<xsd:simpleType name="requiredAnyURI">
		<xsd:restriction base="xsd:anyURI">
			<xsd:minLength value="1"/>
		</xsd:restriction>
	</xsd:simpleType>
</xsd:schema>

Open in new window

Avatar of CloudedTurtle
CloudedTurtle
Flag of United States of America image

I created a quick test form with a StringField, and a RichTextBox (RTB) on the form. I saved a couple of XML files using this form, and then modified the form to change the StringField to a RTB. After I saved the form changes, and then opened the saved XML files, I didn't loose any data.
I recommend creating a small test area where you can work with a duplicate of the form template, as well as a copy of some of the form files (XML) that are saved by this form template. Work with these copies so that if you have any problems you are messing with the saved "production" information.
Here is what I did.
  • Open your form template in Design mode
  • From the View menu, select DataSource
  • Right-click on your field that is the StringValue, and select properties
  • In the DataType Dropdown select  "Rich Text (XHTML)"
    • When you do this, the form element (textbox) on your form will break the binding to the control, this is because you have the wrong control set for the datatype.
  • Select the Control on the Form and Righ Click.
  • Select "Change To", and select "Rich Text Box"
Once this is done, you can save the template, and new form will have the RTB for your field, and any existing for that was created with the earlier version will show the value that was entered in the String, in the RTB.
Note: If you make this change, it is much more difficult to change back to a StringField as you run the risk of loosing more data going this direction.
Hopefully, this helps you to some extent. If you need more details on anything just ask!

Avatar of steam23

ASKER

I think I'm beginning to see where the problem lies, though I'm not sure how it got that way.
I tried to change the Datatype to rich text as you suggested, but the option for Rich text isn't available. When I did I noticed that the Type is set as Field(attribute) rather than Field(element). Judging from my experiments with the myschema.xsd file, it seems that the RichText datatype can't be used within an attribute tag.  I can't imagine I would have set that field as an attribute, but I guess I should stop drinking while designing forms;)
I have a nasty feeling that if I delete the field(attribute) and replace it with a RichText element that I will loose the data in that field. I'm really hoping for a way around this. Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of CloudedTurtle
CloudedTurtle
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of steam23

ASKER

I like the way you think! A little Infopath jujitsu!  I will give it a try and report on the results.
Avatar of steam23

ASKER

Brilliant! that worked perfectly!
Avatar of steam23

ASKER

That did it!
I set the original field to a width of 1 px so it didn't mess with my design, and used conditional formatting to hide the field. The new rich text field is automatically updated on all the forms.
Thanks!
No problem, one more note, technically you can remove the control from the Form Template (as long as you don't delete the field from the datasource) then you don't have to worry about 1px controls in your form.. These might also come to haunt you in the future...
 
Avatar of steam23

ASKER

A quick update for anyone else using this solution.
The fix worked well, but I needed to open each form and resubmit it to the server to populate the new field. Once that was done, I could safely delete the old field.  I had missed this step, and as a result, users tried to edit old forms, and found that their work didn't look like it was being saved, since the next time they opened the form, the new field would be overwritten with the default value of the old field.