RSS
 

Archive for octobre, 2006

How to submit an InfoPath form to a Windows SharePoint Services document library

27 oct

Hi,

That is the last part of a two posts set of articles. We’ve first seens how-to debug MS Script in InfoPath (You can find it here: http://www.e-soft.ca/blogs/index.php?title=how_to_debug_ms_script_jscript_in_ms_inf_2003&more=1&c=1&tb=1&pb=1 ).

This article show you somehting very important. How to submit a newly filled form to a doclib. If you do nto customize your forms do submit them, you need to show your users how to save the form in the document library. That may seems obvious but it isn’t. Because they also need to define the file name and they want to be sure that they did everything properly. There is also a risk that there overwrite an existing form.

Many information for this articale come frmo MSDN article 826993:
http://support.microsoft.com/kb/826993/en-us

First thing you want to do is to create a button to submit the form.

Submit the form data to a SharePoint Services document library
You can use script or the UI to submit the form data to the SharePoint Services document library.

Use script to submit the form data to a SharePoint Services document library in InfoPath 2003
1. On the Tools menu, click Submitting Forms.

The Submitting Forms dialog box appears.
2. In the Submitting Forms dialog box, click Enable Submit.
3. In the Submit box, click Submit Using Custom Script.

Here you can also tick the checkbox to provide a caption to the submit button. I Use “Submit the form.”

In Send options, you can tick “Close the form” after submit

4. Click Open Microsoft Script Editor, and then click OK. If it is checked, uncheck the option to display a message to the user. We will handle this ourself with the script. It makes it very clean for the user.

so… Microsoft Script Editor starts.
5. Modify the OnSubmitRequest event as follows.

Code:

function XDocument::OnSubmitRequest(eventObj)
{
// Modified by YANN
// If the submit operation is successful, set
// eventObj.ReturnStatus = true.
var fSuccessful = false;
// Set the URL of the file that you want to submit here.
var now = new Date();
var time = getTimeString(now);
time = time.replace(« : », »");
time = time.replace(« : », »");
time = time.replace(« . », »");
var date = getDateString(now);
date = date.replace(« - », »");
date = date.replace(« - », »");
var fileName = date + « - » + time + « .xml »;
var strUrl = « https://host.domain.com/sites/SiteName/DocLibName/ » + fileName;
//debugger;
try
{
// Create an xmlhttp object.
var oXmlHttp = new ActiveXObject(« MSXML2.XMLHTTP »);
// See whether the document with the same name already exists in the Windows SharePoint Services (WSS) document library.
oXmlHttp.Open(« HEAD », strUrl, false);
oXmlHttp.Send();
// No document with the URL has been found. Continue to submit.
// If you must replace the original file, you must call
// oXmlHttp.Open(« DELETE », strUrl, false) to delete the document
// in the WSS document library.
if (oXmlHttp.Status == 404)
{
// Put the document in the WSS document library.
oXmlHttp.Open(« PUT », strUrl, false);
oXmlHttp.Send(XDocument.DOM.xml);
// A 200 status code or a 201 status code indicates that the form has been submitted successfully.
if (oXmlHttp.Status == 200 oXmlHttp.Status == 201)
{
fSuccessful = true;
}
}
}
catch (ex)
{//XDocument.UI.Alert(« Error:  » + ex.Message);
}
if (fSuccessful)
{
XDocument.UI.Alert(« Your form was submitted successfully. »);
eventObj.ReturnStatus = true;
}
else
{
XDocument.UI.Alert(« There was a problem sending your form. Therefore, your form was NOT saved. »);
eventObj.ReturnStatus = false;
}
}

From line 9 to 17, We build the filename from date and time. This is what I do to get a unique name for the forms. Of course, you can modify this to fit your needs.

Here is a link to JScript Reference at MSDN to help with the language:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/1e9b3876-3d38-4fd8-8596-1bbfe2330aa9.asp

Note You must change the value of the strURL variable to a valid URL in the code. IT needs to be a valid encoded URL.

6. Save the script. Close Script Editor.
7. Save your form template as SubmitToWSS.xsn.

Use the UI to submit the form data to a SharePoint Services document library in InfoPath 2003 Service Pack 1
1. On the Tools menu, click Submitting Forms.

The Submitting Forms dialog box appears.
2. In the Submitting Forms dialog box, click Enable Submit commands and buttons.
3. In the Submit to section, click SharePoint form library.
4. In the Submitting Forms dialog box, click Add.

The Data Connection Wizard starts.
5. Input your SharePoint Services form library link in the SharePoint form library box.

Your library link may look similar to the following:

http://ServerName/SiteName/DocumentLibraryName
6. Type the document name in the File name box.

You can use a document name such as TestForm.

Click Next.
7. In the Data Connection Wizard, click Finish.
8. In the Submitting Forms dialog box, Click OK.
9. Save your form template as “SubmitToWSS.xsn.”

Back to the top

Test your form
1. On the File menu, click Fill Out a Form.
2. In the Fill Out a Form task pane, click SubmitToWSS.
3. Complete the form.
4. On the File menu, click Submit.

If the form is submitted successfully, you receive a message that indicates this.

5. If you ticked the checkboxes as I recommanded earlier, this point is not used: “Quit InfoPath. If you are prompted to save your changes to the form, click No. “

6. Start Microsoft Internet Explorer. Locate your document form library.

For example, your document form library may be http://ServerName/SiteName/DocumentLibraryName.

A new item that is named in the document library.
7. Click the newly created item.
The form that you submitted opens in InfoPath 2003.

 
 

How-to Debug MS Script (JScript) in MS InfoPath 2003

27 oct

This article as two parts. This one shows how to debug MS Script (JScript) in MS InfoPath. The second one, provide the information to submit a newly completed form to a Document Library (Form Library) in Sharepoint.

Part Two is overhere:
http://www.e-soft.ca/blogs/index.php?title=how_to_submit_an_infopath_form_to_a_wind&more=1&c=1&tb=1&pb=1

Note that most of what you’ll read comes from MSDN, but with added code and comments.

Before going any further, I have to warn you about a possible failure with the MS Script Editor. If it crashes every time you try to open the code (the editor) you may encounter the same problem I had. It is caused by splitted Office Software installation. I won’t go into a lot of detail on the « Why », but just let you know that it can be fixed by running the MS Office Setup again and doing a Reinstall.

If you want to read mroe about it, see the KB article 898789:
http://support.microsoft.com/kb/898789/en-us?spid=2515&sid=251

So here is How-to Debug…

Step-by-Step
1. Start InfoPath 2003.

2. On the File menu, click Design a Form.

3. In the Design a Form task pane, click New Blank Form.

4. To add the following script to your form, follow these steps:
a. On the Tools menu, point to Script, and then select On Load Event.
Microsoft Script Editor appears.
b. Add “debugger;” to the OnLoad function. See the following code:

JScript

Code:

ode>function XDocument::OnLoad(eventObj)
{
debugger;
}

VBScript

Code:

ode>Sub XDocument_OnLoad(eventObj)
Stop
XDocument.UI.Alert « This is a test. »
End Sub

c. Save the script, and then close Script Editor.

NOTE: This will make the debugger to stop at the beginning of the code execution. If you want to step directly to another part of your code, add “debugger;” at the line you want the debugger to stop.

This way, you can hit F5 after the debugger open on the first debugger line. Or as for Visual Studio, use F10, F11 etc. You’ll be able to see the variable values by doing onMouseOver.

5. On the File menu, point to Preview Form, and then click Default.

6. The Just-In-Time Debugging dialog box appears. Select New Instance of Microsoft Script Editor in the list of possible debuggers, and then click Yes.

The Step Into Remote Procedure Call dialog box appears. Click OK.
Your script appears in Script Editor and the script execution stops.

Note If Script Editor appears but your code does not appear, then you may have to install the Web Debugging feature for Script Editor. For details, see the following “Install Web Script Debugging” section.

7. Press F10 to move through the remaining lines of code in your script.

One last detail, “Comment” you debugger lines when you’re done. Because it would be compiled as an error when someone fill a new form.

Enjoy!

 
 

My first MCP!

13 oct

Hi,

After so many years working in computer systems, I finally get myself to study for some Microsoft Certifications. Yesterday I got my first MCP.

I’d like to say it was easy, but is wasn’t . I guess that is why I am proud to have achieved this goal at my first try.

 
No Comments

Posted in Career