This project has moved and is read-only. For the latest updates, please go here.

Using UpdateListItems to create new item of specific Content Type

Oct 20, 2011 at 1:43 PM

I am trying to do the standard UpdateListItems to create a new list item with a twist - I need to preload the ContentType.

It works fine, but always brings in the default Content Type - if there a different value I should be using, comparable to a Internal Field Name for a standard column?  ContentID?  I am creating a page where a user can click on individual buttons that create the items of different content types , bringing in a bunch of current user info:

function CreateObservation(office,company,outlookEmail,officeId,companyId)

        operation: "UpdateListItems",
        async: false,
        listName: "{7C4F1E06-F29D-4ABC-A959-DE0B896041F6}",
        updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
                    "<Method ID='1' Cmd='New'>" +
                        "<Field Name='ContentType'>Electric Specific Observation</Field>" +
                        "<Field Name='Title'>Please enter Job Description</Field>" +
                        "<Field Name='Observer'>-1;#" + outlookEmail + "</Field>" +
                        "<Field Name='Supervisor'>-1;#" + outlookEmail + "</Field>" +
                        "<Field Name='Office'>" + officeId + ";#" + office + "</Field>" +
                       "<Field Name='Company'>" + companyId + ";#" + company + "</Field>" +
                    "</Method>" +
        completefunc: function (xData, Status) {

 //now that the item has been created, we need the ID of the new item:

            var observationId = $(xData.responseXML).find("[nodeName=z:row]").attr("ows_ID");

// using the ID, we direct the user to the new item in edit mode, so they can finish filling in the information

window.location = ("http://idnet/sites/dvpdem/Lists/Observations/EditForm.aspx?ID="+ observationId)

Oct 20, 2011 at 7:31 PM
Edited Oct 20, 2011 at 7:32 PM

Actually, one additional bit of info, it does not bring in the Default ContentType, it actually brings in Driving Observation, which would be the first choice if I sorted ContentType alphabetically.  My ContentTypes are:

  • Electric Specific Observation (the default)
  • Driving Observation
  • PPE Observation
Oct 20, 2011 at 7:39 PM

OK - resolved - was a simple error on my part.  I added multiple buttons on the page and failed to rename my functions from one to the next, so it chose the update list items that was last loaded.

Thanks for any who peaked in!

Oct 21, 2011 at 2:33 AM
Glad you solved it!