Create New List Items - code help req

Jul 23, 2010 at 7:21 PM
Edited Jul 23, 2010 at 10:24 PM
I am testing some code out but can't figure out where I'm going wrong with my test code, and need some help. Below is my code, have 2 text HTML input fields for the user to enter the data, namely Title and ABC. After the user enters the data, the data then gets dumped into the SharePoint List called "Request Services" All works good but for some odd reason when the user clicks on the Submit button, both the values of Title and ABC Title get dumped into the Title field of the SharePoint List as 2 entries, rather then it being one single entry where the user entered values in the text box getting pushed into the Title and ABC Title field respectively. Also, my plan later on is to give the user the the ability to Attach Documents, i'm reading up on it but have mixed feelings about attachments working with SPServices. Anyone been successful with the implementation? Thanks for the help in advance. ...
</head>
<body>

	Response:
N/A
<script language="javascript" type="text/javascript" > $(document).ready(function() { $("#newTaskButton").click(function() { CreateNewItem($("#newTaskTitle").val()); CreateNewItem($("#newTaskDesc").val()); }); function CreateNewItem(title,desc) { $().SPServices({ operation: "UpdateListItems", async: false, listName: "Request Services", valuepairs: [["Title"], ["ABC"]], updates: "<Batch OnError='Continue'>" + "<Method ID='1' Cmd='New'>" + "<Field Name='Title'>" + title + "</Field>" + "<Field Name='ABC'>" + desc + "</Field>" + "<Field Name='ID'></Field>" + "</Method>" + "</Batch>", completefunc: function(xData, Status) { // Process the result. var out = $().SPServices.SPDebugXMLHttpResult({ node: xData.responseXML, outputId: "#responseStatus" }); $('#responseStatus').html("").append("This is the output from the UpdateListItems operation:" + out); $('#responseXML').append("Refresh to see the change in the list above."); } }); return true; } }); </script> Request Title: <input id="newTaskTitle" type="text" /> ABC Title: <input id="newTaskDesc" type="text" /> <input id="newTaskButton" type="button" value="Submit" /> </body> </html>
Jul 23, 2010 at 11:31 PM
no worries....:). I fig it out from the site
http://sympmarc.com/2009/12/08/a-jquery-library-for-sharepoint-web-services-wss-3-0-and-moss-real-world-example-part-1/
thanks M for creating SPServices :)
Coordinator
Jul 24, 2010 at 12:22 AM
Edited Jul 24, 2010 at 12:57 PM
Looks like you are calling CreateNewItem twice on the button click, once passing the Title value and once passing the Desc value. You probably only intend to call it once with both values. M.
Jul 24, 2010 at 12:32 AM
exactly M - it hit me a little later that I was calling CreateNewItme twice, anyhow I moved from that code and found the workaround from your site. It's tempting for newbies like to keep asking questions, where in fact all the answers are in front of us :) a little reading, some out of the box thinking, and not giving up attitude is rewarding :). Now the one thing I do need your help with is "AddAttachments" - any help is appreciated (I'm reading content here and seeing if I can achieve it ). Again, thanks for the work you have done for the community :)
Coordinator
Jul 24, 2010 at 12:59 PM
What's you question about AddAttachments? Unfortunately, I don't know of anyone who has a solution that is only script to upload a file. M.
Jul 24, 2010 at 9:14 PM

M - I'm currently reading up on how Attachments work in SharePoint List from an article published on EUSP http://www.endusersharepoint.com/2010/01/22/sharepoint-list-attachment-technical-brief/ . I'm thinking about a few things regarding attachments but I believe I should first be reading up on how attachments work internally before I ask the community further questions. :) thx for your reply.

Coordinator
Jul 25, 2010 at 4:07 AM

Michael's a great guy and helps me out here at SPServices from time to time. Shoot him questions and I know he'll answer. Also feel free to keep the discussion going here and I'll help if I can.

M.

Jul 26, 2010 at 7:29 PM
M - I will start the dialogue with Michael, thx for referring him. Here is what I was thinking regarding attachments - I don't know how to go about doing all I mention but it's just a thought which I can refine later with your suggestions as well as help from the community, provided it's doable. 1. To implement $().SPServices.SPRedirectWithID: Let the user fill in all the information on CustomNewForm.aspx and send all that data via the $().SPServices({ operation: "UpdateListItems",..... (this works fine for me, as all data on the form does get entered into the SharePoint List I have called "Request Services". Question? When the users Submits the CustomNewForm.aspx save the form data in "Request Services" and simultaneously redirect the user to a separate SharePoint Document Library called "Upload" via SPRedirectWithID to upload documents? With SPRedirectWithID I get to keep the unique ID created in "Request Services" which will later on match with the ID created in DocLib "Upload" I'm aware my above proposed solution is "so-so" as its a workaround provided it's feasible. Also, I would like to get the job done via $().SPServices({ operation: "AddAttachment",..... polarbear_ch has posted a new thread about his success with attachments and I'm looking into it, but have had no success as him.