Maintaining Text Formatting for Queried Text

M

Mauryaguru

Scenario:
======
I have an Infopath form called "Issue". Any one Issue can have many child
Action Items. The Action Items are stored as a separate SharePoint List.
Action Items are filled out on a separate form called "Action Item". From the
parent Issue Form, I query the SharePoint List of Action Items, and display
all the Action Items in the Issue form.

An Action Item form has two controls:
1) A Text Box field called "Details"
2) A File Attachment field called "Attachment"

In the Issue form, I have a repeating section with contols, to hold the
queried Action Items.

Problem:
======
1) One control in the repeating section to hold the queried Action Items is
a Text Box called "Details". This is bound to the Details field (obtained
using a Query of the Action items list) in the Action Item.

What I find is that the text obtained from the Query of the Action Items
List does not have any of the formatting that was originally entered in the
original Action Item form. (However, if I go to the original Action Item
form, the text in the Details text box is formatted nicely, just as when I
had originally filled the form).

When I say "FORMATTING", here is an example of what I mean: Let's suppose I
entered 2 paragraphs of text into the Details text box in the original Action
Items form, and separated the paragraphs with a full line of space by
pressing Enter. When this text is queried from the Issue form, the space
between the two paragraphs is eliminated, and the second paragraph starts
where the first ends. So if the first paragraph ends in the middle of a
line, the second begins in the middle of that line.

Even with "Paragraph Breaks" checked on the "Display" tab of the "Text Box
Properties" of the "Details" field in the repeating section to hold the
queried Action Items in the Issue form, the best I get in the queried text
for a whole line separating two paragraphs in the original text, is a mere
space.

How can I get the same text formatting in the queried text, as the original
text?

2) Is there any way I can query from the Issue form, or at least provide
some kind of link from the Issue form to, the attachment (could be file or
picture) attached to an Action Item in the Action Item form?

Thanks in advance. This is a bit urgent, so any help would be appreciated.

Mauryaguru
 
W

wjasonstrutz

See response inline:

Mauryaguru said:
======
1) One control in the repeating section to hold the queried Action Items is
a Text Box called "Details". This is bound to the Details field (obtained
using a Query of the Action items list) in the Action Item.

What I find is that the text obtained from the Query of the Action Items
List does not have any of the formatting that was originally entered in the
original Action Item form. (However, if I go to the original Action Item
form, the text in the Details text box is formatted nicely, just as when I
had originally filled the form).

I've run into similar problems when submitting data to an SQL database, then
viewing that text in a Sharepoint Web Part. I believe it's an issue with how
Infopath interprets newlines vs. Sharepoint, but I'm not certain. Try using
different combinations of characters for the newline; I've found the '\r\n'
(carriage return, newline) work best for my apps. Sorry I can't be of more
help with this.
2) Is there any way I can query from the Issue form, or at least provide
some kind of link from the Issue form to, the attachment (could be file or
picture) attached to an Action Item in the Action Item form?

You could have the Action Form just be a second view of the Issue Form. For
SQL Server connections, this is easy (just add the second table to the Main
Data Source), but I'm not sure if it can be done when using a Sharepoint list
as the data source.

You can link to the Action form from the Issue form. In your repeating
section or table that displays Actions, add a button that uses custom code.
In the custom code, open the Action form, select the query node for the
Action ID (or some other identifying fields), and query the main data source.
The code would look something like this (in jscript):

var theIssue = // select the issue id from main data source

// points to the form template for the Action form, assuming it's published
to a
// Sharepoint form library
var strTemplatePath = "http://my-server/Action/Forms/template.xsn";

// open the form
var actionDoc = Application.XDocuments.NewFromSolution(strTemplatePath);

// set the query value so it opens only the actions associated with this issue
newDoc.DOM.selectSingleNode("//q:Action").setAttribute("issue_id", theIssue);

// run the query
newDoc.Query();

Again, this is how it would work if the form is based on an SQL Server data
source. I'm not sure if the procedure would be exactly the same for forms
based on Sharepoint lists.

HTH,
jason.
 
M

Mauryaguru

Hello Jason
Thanks for the reply.

1) When you say using /r/n to enforce good paragrpahing in the queried
text, what do you mean? Does this mean that when I originally put the text
in the Action Item, then I should end each paragraph with /r/n? I tried
doing this with quotes ("/r/n") and without quotes (/r/n), put this does not
cause the paragraph formatting to happen in the queried text, all I see is
whatever I typed (i.e. /r/n or "/r/n").

2)
a) You say "In your repeating section or table that displays Actions, add a
button that uses custom code." So here, you are saying that a button is to be
pressed in the Issue Form to do the query, and to show in another view, the
associated Action items, correct?

b) One of the lines of code you provided was:
newDoc.DOM.selectSingleNode("//q:Action").setAttribute("issue_id", theIssue);

Two questions:
i) "//q:Action" is simply what you are calling the Action Items (SharePoint)
List, correct?
ii) "issue_id" is simply a field in an Action Item that stores the unique
parent Issue's ID (basically a key), correct?

Jason, thanks for being so helpful.

Mauryaguru
 
W

wjasonstrutz

Mauryaguru said:
Hello Jason
Thanks for the reply.

1) When you say using /r/n to enforce good paragrpahing in the queried
text, what do you mean? Does this mean that when I originally put the text
in the Action Item, then I should end each paragraph with /r/n? I tried
doing this with quotes ("/r/n") and without quotes (/r/n), put this does not
cause the paragraph formatting to happen in the queried text, all I see is
whatever I typed (i.e. /r/n or "/r/n").

Careful, use a backslash instead of a forward slash. /r/n will just print
"/r/n", but \r\n will print [carriage return][newline]. The backslash is
used to escape the character, so instead of printing r, \r will print a
carriage return. By the way, if you wanted to print a backslash, you would
use \\.

And yes, the \r\n should be in quotes. Use them just like you would any
other string.
2)
a) You say "In your repeating section or table that displays Actions, add a
button that uses custom code." So here, you are saying that a button is to be
pressed in the Issue Form to do the query, and to show in another view, the
associated Action items, correct?

Yes, but through script. In the button properties, set its action to Rules
and Custom Code. When you click on Edit Form Code in the button properties,
Microsoft Script Editor will open and create the function for you.
b) One of the lines of code you provided was:
newDoc.DOM.selectSingleNode("//q:Action").setAttribute("issue_id", theIssue);

Two questions:
i) "//q:Action" is simply what you are calling the Action Items (SharePoint)
List, correct?

Not exactly. When you add a secondary data source, the XML structure for
the source can be accessed through the selectSingleNode method (or
selectNodes, if you want to get a whole group) of the DOM (Document Object
Model) object. The parameter for this function is an XPath, represented as a
string, that specifies where to find the XML node in the XML tree.

In XPath, "/" refers to the root node, "//" means start at the root node and
find the first thing that matches the rest of the path. The text after the
slash and before the ":" is the namespace, which is automatically defined by
Infopath. The text after the ":" is the node name. Putting it together,
XDocument.DOM.selectSingleNode("//q:Action") starts at the root and searches
for the first node that has namespace "q" and node name "Action".

There is a whole lot more information about XPath, and all of it applies to
Infopath, but I won't go into that here. A web search for XPath should yeild
some good references.
ii) "issue_id" is simply a field in an Action Item that stores the unique
parent Issue's ID (basically a key), correct?

Yes. When you create a secondary data source, tables (and lists) are mapped
to groups in the Infopath data source. Infopath then adds all the fields in
the data source as attributes. Attributes do have namespaces, but you don't
have to specify them because they actually reside inside the tag that is
their parent.

Here is a sample XML structure that does not use attributes, but has fields
specified as individual tags. Typically when you add items to the data
source through Infopath you will get a structure like this:

<my:person>
<my:FirstName>Jason</my:FirstName>
<my:LastName>Strutz</my:LastName>
</my:person>

In this case, the data nodes are selectable, so you can do
XDocument.DOM.selectSingleNode("//my:FirstName") to see the value.

If instead we create the same structure from a database table named Person
that has fields for FirstName and LastName, we get this structure:

<my:person FirstName=Jason LastName=Strutz></Person>

Here, the actual data isn't selectable; it's hidden within a Person node
(that is likely a repeating field). In this case, we have to get the data by
doing XDocument.DOM.selectSingleNode("//my:person").getAttribute("FirstName").

jason.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top