Howto: Submit to a Word Form library in Sharepoint Services

P

Patrick Temple

I have two seperate Word Form Libraries in my Sharepoint site. These are
additional documents to support the information in the main infopath form. I
need to create these docs when the form is in use. I tried submitting to a
form library and concatonating the filename into a ".doc" file but Infopath
tacked on ".xml" to the end of it and made it an XML file.

Any ideas on how to submit to a Word Form Library to create a Word doc not
an XML file? I want to tie the functionality into a button. Not Javascript
or VBscript guy but assuming there's a behind the scenes approach using the
"Edit Form Code" option for buttons.

Any help would be appreciated.

Thanks
 
S

Scott L. Heim [MSFT]

Hi Patrick,

Can you clarify something for me? If I understand correctly you are trying
to accomplish the following:

- Open an InfoPath form based on an InfoPath template (i.e. double-click
an XSN file or click Fill out this form from a Sharepoint site)
- Fill out the form with data
- Submit this form to a "Word" library and actually turn this into a Word
document instead of an InfoPath XML file

Is this correct or am I misunderstanding what you are trying to accomplish?

Thanks,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Patrick Temple

Scott,

Not exactly but close. Let me clarify

I actually will end up with 3 seperate documents.
1) The infopath form (A Requirement)
2) A word doc that contains extra information about a specific topic within
the Requirement
3) A word doc that contains a much more detailed layout of the Requirement

The information for the Requirement is stored in a SQL Server Database but
the other two docs will be stored in Sharepoint Libraries. When a user
creates a new requirement, I need to also create the corresponding Word docs
in their respective libraries. Using the ID number as their titles. I have
fields in my database set up to hold the links to these files as text. I
then use the hyperlink function of Infopath to turn them into hyperlinks

I have some code that should work but I'm stuck on getting the idNumber into
the code.

//Code to submit to a Word Doc library.

var eventObj, refID, type, refIdInt, docfolder, doclink, templatetype, file,
pathName;

//Get id number information
Stuck HERE!! --> refID =
XDocument.DOM.selectSingleNode("\myFields\dataFields\d:requirement_sfp\idNumber").text; <-- Stuck HERE!

//Turn refID into a 5 digit number
refID = (refID + .1) * .00001;
refID = refID.substring(2,2);

//Return the first two digits of the id number - e.g. 02394 to 02
refIdInt = refID.substring(0,2);

//Build the document folder path - e.g. "2k-2999"
docfolder = (refIdInt * 1000) + "-" + ((refIdInt * 1000) + 999) + "/";

//Get template and copy file
eventObj = new ActiveXObject("Scripting.FileSystemObject");

file =
eventObj.GetFile("//ljpl.boi.hp.com/Requirements/Templates/AddLongDescTemplate.doc");

pathName = "//ljpl.boi.hp.com/Requirements/AddLongDescDoc/" + docfolder +
refID + ".doc";

file.copy(pathName, false);

I know this code works when using an XML file as my datasource but doesn't
seem to work when using a database as my datasource. I get a Jscript runtime
error about needing an Object.

Hope that clears it up for ya, could really use an answer for this one.

Thanks again
 
S

Scott L. Heim [MSFT]

Hi Patrick,

Thank you for the clarification. So based on your update, you simply need
to determine the correct "XPath" to get the value field value from your
form.

Based on what you have provided, this is indeed incorrect:

refID =
XDocument.DOM.selectSingleNode("\myFields\dataFields\d:requirement_sfp\idNum
ber").text

If your main InfoPath form is bound to SQL Server, then typically the XPath
would look like this:

refID =
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:requirement_
sfp/@idNumber").text

Let's see if this change helps...

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Patrick Temple

Scott,

Closer but not quite there yet.

So I had to remove the ".text" from the end of the line. Sense idNumber is
an integer, the ".text" kept giving me the "Object" error.

It appears that both our lines of code worked once I did that. I get all
the way to the end of the script to:

file.copy(pathName, false);

before it errors. My guess is the variable "pathName" is wrong for the copy
command. Sense it uses idNumber to build part of the path.

I'm working in the blind though, because I haven't figure a way to return
the "idNumber" value to the screen so I can see what it is after I do the
math and substring commands on it. I tried window.alert(idNumber) but got
some sort of window undefined error. Is there a nice pop up or alert box
function that will work in Infopath for this?

I could try setting one of my text fields in my form to the value but not
sure how to do that either. Anyway, let me know what you think.

Thanks again.

--Patrick Temple
Microsoft Developer Support Headache Creator.
 
S

Scott L. Heim [MSFT]

Hi Patrick,

You can use the following script to display a message box:

- VBScript:
XDocument.UI.Alert idNumber

- JScript:
XDocument.UI.Alert(idNumber);

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Patrick Temple

Scott,

Thanks, that really helped. It turns out that idNumber was "null" because
the script is running before the submit to the database to create the new
idNumber. So I just need to move the script to a point after the initial
submit and I think were in business.

Thanks this was extremely helpful. =)

--Patrick Temple
 
S

Scott L. Heim [MSFT]

Hi Patrick,

Excellent!

Best of luck with this...

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Patrick Temple

Scott,

Looks like I mispoke earlier. After doing some debugging using the popup
code you gave me. idNumber isn't getting retrieved. It just returns "null"
The rest of the script works with dummy numbers so the only sticking point is
getting the idNumber.

refID =
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:requirement_
sfp/@idNumber")

returns a "null"

Any ideas?
 
S

Scott L. Heim [MSFT]

Hi Patrick,

Just to be sure (this may have been a typo on your part) - in order to
actually get the value you would need to have one of the following:

refID =
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:requirement_
sfp/@idNumber").text

Or something like this:

Dim objRefID
Set objRefID =
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:requirement_
sfp/@idNumber")

refID = objRefID.text

What I am indicating is we need to get to the "text" property to get the
actual value.

Let me know if this helps any...

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Patrick Temple

Scott,

So I tried both, the first line of code gave me an "Object Required" error.

The second set gave me a "; expected" error. I added the semicolons but I
think the problem there is that looks like VBscript code and this is a
Jscript file. Just guessing from the "Dim" call.

I get what your saying about the "text" property. The value is actually an
Integer, do we need to adjust for that?

Sorry for the headache. You've been really helpful though.

--Patrick
 
P

Patrick Temple

Scott,

Nevermind the last post, I figured it out. I had the path wrong. Once I
corrected it to the right path your code worked GREAT!!

Thanks alot for all the help and sticking with me on this one.

Keep up the great work.

=)

--Patrick
 
S

Scott L. Heim [MSFT]

Hi Patrick,

Sweet! :)

Thanks for letting me know you've got it working!

Take care,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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