Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Changing a field type programmatically?

Avatar

Level 4
We have a form that generates an XML file that is emailed to Word Processing to get merged into a Word document. The form uses a table to totalize some columns. The client now wants any cells in which the value is null to read "N/A" in the Word document. It's easy enough to make the form *display* N/A, but to put "N/A" in the fields so that the word processor doesn't have to search and replace, I'd like to change the affected fields to text fields programmatically and set them to "N/A" so thst the XML file fields would have the "N/A" value that would be picked up by the Word mailmerge.



Is there a way to do that?
6 Replies

Avatar

Former Community Member
How big is the form? How many fields? If it is not too big you could loop through each onject in the form, test its value and if it is null set it to N/A. Or you could have an initial value of NA instead of null.

Avatar

Level 4
It's 8 fields, well 9 if you count the total field, so I really don't even need to loop through the entire form. The fields are numneric so that if there's a number that is input, the total field will totalize properly. The problem is that the 8 fields are scattered throughout the Word document so if I could have the XML output file values for the fields be "N/A" instead of null or "00", it would save the word processors time doing search and replace.

Avatar

Former Community Member
Once you change the field value to NA then the calc will refire and an error will be generated because you are adding a string to an float.

Avatar

Level 4
Yup. That's what I thought, so it's not possible to change the type of field from numeric to string if the value is null?

Avatar

Level 4
Well, win some, lose some! :-) Since it's a relatively small number of fields, I think I'll just set up some additional text fields, and if the numeric fields aren't null, load the text fields with the numbers as strings since they've been totaled already. If the numeric fields are null, load the text fields with "N/A". Then I can have Word pick up the text fields instead of the numeric fields.



Thanks for getting back to me.