Submitting to Sharepoint using custom code

H

Hosehead17

Here is the setup, we have these forms to track certain processes at
our company. We want to move the forms out of the "pending" folder
and into the "completed" folder. I have a drop down box defined as
status and I have setup custom rules to submit the form using a
different data connection depending on the value of status. The only
problem we have is that we have to go in and manually remove the old
forms out of the pending folder. Simply put, when the status changes
to completed and the form is submited, the form should have been moved
to the completed folder. I have tried writing custom code, in java
script to do this, but I have run into a few problems: 1). How do
open the file for overwriting? I can submit the form if no form
exists, but if I open the form from the Sharepoint site later to make
changes the code for submit doesn't work, but if I hit save it will
save the changes up to the site. I would like to just be able to tell
the users to use the submit button (this works when I use the data
connections and custom rules!). Is there a way to reference the data
connections that are defined in the manifest? 2). Once that works,
how do I delete the document from one folder and submit it to the
other folder. Mainly, how would I delete it is the part of it that I
don't know, but there could be a pit fall to doing both.

This is the code that I am working with, I haven't started working on
the part to submit it to the 2nd location, I've just been working with
the first problem:

function XDocument::OnSubmitRequest(eventObj)
{
// 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 fname = XDocument.DOM.selectSingleNode("//my:myFields/my:Filename");
var strUrl = "http://aosvs1/RMA/RMA Tracking Form/Pending RMAs/"
+ fname.text + ".xml";
var SubmitDest;

try
{
// Create an xmlhttp object.
var oXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");

XDocument.UI.Alert("We are starting now");
// Check whether the document with the same name already
exists in the Windows SharePoint Services (WSS) document library.
oXmlHttp.Open("POST", 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)
{
XDocument.UI.Alert("No file was found, proceeding");
// 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;
}
}
else
{
//XDocument.UI.Alert("Well, a file was found, so trying to
delete it");
//oXmlHttp.Open("POST", strUrl, false);
//oxmlHttp.Send();

XDocument.UI.Alert("We are trying to put the document on the
server now...");
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){}


if (fSuccessful)
{
XDocument.UI.Alert("Document submitted successfully.");
eventObj.ReturnStatus = true;
}
else
{
eventObj.ReturnStatus = false;
}


}

Thanks in advance!
 

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