How to submit infopath form using custom form code?

V

Victor

Hi, i have an infopath form that needs to generate an auto-increment invoice
no which i have written a stored procedure to increment the invoice no
everytime the user submits a new form. But i need to put the auto-increment
stored procedure in OnSubmitRequest subroutine so that everytime i click on
Submit, the stored procedure will be called to execute the auto-increment
function. My problem is i don't know the custom form code to submit the form
to sharepoint. I am using VB Script. I have searched for the source code but
very limited and not solving my problem. Can anyone provide the scripts code
in submitting a form to sharepoint? Your help is very much appreciated.
 
V

Victor

Isn't Infopath has sample source code in submitting a new form to sharepoint
in VB Script?

If there is, how come there is none reply to the question posted? Or have i
posted to the wrong newsgroup?
 
V

Victor

Thanks S.Y.M for being so helpful.

I have followed your instruction to convert Jscript to VBScript to be
applied in my form.

When i run the form, there is an error message prompted " Object required:
strUri"

I have no problem to run the JScript codes in my new form but have this
error using VB Script.

So, i think there must be some syntax error in VB Script.

I will post the script that prompted the error message at the bottom. The
error encountered at the PopulateLibInfo subroutine for strPath. Please help
me to take a look at what has gone wrong.

Thank you.


Sub XDocument_OnLoad(eventObj)
'Get the Uri of where the form was opened
strUri = XDocument.Solution.URI

'Populate the fields on the form - keep in mind, this is not necessary -
'this is simply to see the process in action
PopulateLibInfo
End Sub

Sub PopulateLibInfo

'Create IXMLDOMNode objects for each field
dim xnFormURL
set xnFormURL =
XDocument.DOM.selectSingleNode("my:myFields/my:strFormURL")
dim xnLocation
set xnLocation =
XDocument.DOM.selectSingleNode("my:myFields/my:strLocation")
dim xnFolderName
set xnFolderName =
XDocument.DOM.selectSingleNode("my:myFields/my:strFolderName")

'Create a variable to store the path (URL) to the document library
dim strPath

'Parse just the path to the document library -
'this would return something like this: http://server/library

strPath = strUri.substring(0, strUri.indexOf("Forms") - 1)

'Now, parse the URL to where the document library resides -
'this would return something like: http://server or http://server/site
dim strLoc
strLoc = strPath.substring(0, strPath.lastIndexOf("/"))

'Lastly, parse the URL to return just the document library name -
'in this case,we are looking for the last "/" character
'knowing that what comes after this is the document library name
dim strFolder
strFolder = strPath.substring(strPath.lastIndexOf("/") + 1)

'Populate the fields on the form – we will use these values
'in the Submit process

xnFormURL.text = strUri
xnLocation.text = strLoc
xnFolderName.text = strFolder

end sub
 
S

S.Y.M. Wong-A-Ton

You're getting 'Object required' because strUri is not an object, it is just
a string, meaning that it has no methods or properties.

strUri.substring(...)

is not correct VBScript syntax. You need to use the VBScript "Mid" function
instead of "substring" (see
http://msdn2.microsoft.com/en-us/library/wffts6k3.aspx). I haven't analyzed
the code to see what it is actually doing, but it shouldn't be too difficult
to figure out. And before you bump into another error, you must use the
VBScript "InStr" function instead of "indexOf" (see
http://msdn2.microsoft.com/en-us/library/wybb344c.aspx). Do the same for the
code using strPath.

Hope this helps.
 
V

Victor

Good morning S.Y.M. Wong,

Follow your instruction, i have managed to get the strUri, strPath
and strLocation using Mid and instr functions. Thank you very much!

Now i have another problem. My problem is Object doesn't support this
proerty or method. I have checked on my source code and found that the error
came from
dim fc
fc=XDocument.DataAdapter("Main submit")

I think this is once more VBScript syntax error. VBScript should have
another way to create connection. Can you kindly show me? Thank you!

One more thing is

I would like to capture the exception during the submission but i
don't know how to do that in VBScript. Please correct my source code below:

try
fc.submit
eventObj.returnstatus=true
catch(ex)
eventObj.returnstatus=false

Will this work?

Thank you.
 
S

S.Y.M. Wong-A-Ton

fc=XDocument.DataAdapter("Main submit")

needs to be

Set fc = XDocument.DataAdapters("Main submit")

Notice the extra "s" on "DataAdapters"? As for catching errors, you must use
"On Error Resume Next" just before the line you want to check, and then test
whether Err.Number <> 0 just after the line you want to check. If Err.Number
<> 0 an error occurred.
 
V

Victor

Hi, S.Y.M. Wong,

Thanks for telling me the mistake i made in setting up the connection. Now,
i managed to establish the connection.

Thanks also for providing me with the source code to capture the
exception.

I still face problem in submitting the form. I can get the form
submitted but there is an error prompting my submission failed. However, when
i go to the sharepoint to see, the form is submitted. I put a display of
message in the if err.number<>0, the message displayed.

What could be the error?

My Submit function written like this:

Sub XDocument_OnSubmitRequest(eventObj)
' If the submit operation is successful, set
' eventObj.ReturnStatus = True
' Write your code here

'Create string objects for each field we will use to modify the FolderUrl
dim xnLocation
xnLocation =
XDocument.DOM.selectSingleNode("my:myFields/my:strLocation").text
dim xnFolderName
xnFolderName =
XDocument.DOM.selectSingleNode("my:myFields/my:strFolderName").text

'Get a reference to the submit data connection

dim fc

set fc=XDocument.DataAdapters("Main submit")

'Modify the Submit connection URL we want to submit to by concatenating the
'xnLocation and xnFolderName values
fc.FolderURL = xnLocation + "/" + xnFolderName
'Execute the submit connection

dim err

on error resume next

fc.Submit

if err.number<>0 then
msgbox err.Description
err.clear
end if

End Sub

Can help me to troubleshoot my erorr?

Thank you!

Rgds,
Victor
 
S

S.Y.M. Wong-A-Ton

Thank you, Victor. I often get that from people like you, who do not realize
that there are other people in the newsgroup who also need help. I only have
less than 15 hours within a day to work to put bread on my table, and then
help people like yourself for free in the time that I have left.
 
V

Victor

OK. Understand your situation now. I can see that you are helping out many
people including myself for free even beyond your working time. Because i
noticed that there was once you replied my query at night around 10 something
pm. So, i could figure that you are doing it after your working time as well.
Thanks. Really appreciate that. So, will you be answering questions that i
post in the future?
 
S

S.Y.M. Wong-A-Ton

That's a difficult question to answer, since I do not know whether I will
still be here to answer any questions. I do not have criteria when answering
questions in the group. If I know the answer and have time to answer, I will
answer. If I do not know the answer and have time to answer, I won't answer.
So you see, it is not that clear-cut.
 
V

Victor

Ok. No problem. Can you provide me with some resources or references on
coding Infopath form using Microsoft Toolkit 2003? This is because i find
that Microsoft Toolkit will be quite useful in developing Infopath form and i
would like to explore and learn more on how to use Microsoft Toolkit in
solving Infopath problems.

Thank you.
 
S

S.Y.M. Wong-A-Ton

As far as I know, there aren't any toolkit specific resources online, but you
can repost your question to see if someone else knows of any resources, since
I am not the only one who provides answers in this newsgroup. :)

Your best bet to learn to program for InfoPath is to go to:
http://blogs.msdn.com/infopath
http://www.infopathdev.com

or to buy a book like "Developing Solutions with InfoPath" from Microsoft
Press. Consulting the InfoPath SDK might help too.
 
V

Victor

Thanks a lot. I will repost my question to gather useful information. Thanks
for the helps!
 

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