Updating a List from a Survey w/o Workflow

Dec 1, 2009 at 5:02 PM

Dear Marc,

How do I get started with this?

You suggested I use your jQuery library to call the web service UpdateListItems on completion of a survey to store the survey ID in the report that it's linked to. Sounds like just what I'm looking for, but how do I do it?

Blessings,
Jim Bob

Coordinator
Dec 1, 2009 at 5:21 PM

Jim Bob:

If you look at the bottom of the Documentation page, you'll see the basic setup.  What you'll want to do is use the UpdateListItems operation.  The call will look something like this:

$().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Injury Report",
   updates: "<Batch OnError='Continue'/>" +
     "<Method ID='1' Cmd='Update'>" +
      "<Field Name='ID'>" + BPEId + "</Field>" +
      "<Field Name='SurveyID'>" + surveyId + "</Field>" +
     "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
    ..do stuff, if needed...
   }
  });

I'll be around this afternoon if you have questions along the way.  I may be away from my computer from time to time.

M.

Dec 1, 2009 at 6:39 PM
Edited Dec 9, 2009 at 7:21 PM

So, I'll need to wrap this in a conditional that checks to see if we're "Finish"ing the survey, right? Haven't quite gotten that far yet, but here's what I've done. Please let me know if I've modified the right parts:

 
 $().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Work-related Injury or Illness Report",
   updates: "<Batch OnError='Continue'/>" +
     "<Method ID='1' Cmd='Update'>" +
      "<Field Name='ID'>" + Incident_x0200_Report + "</Field>" +
      "<Field Name='SurveyID'>" + ID + "</Field>" +
     "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
    ..do stuff, if needed...
   }
  });
Thanks!
Jim Bob
Coordinator
Dec 1, 2009 at 8:48 PM

Jim Bob:

Sorry for the delay in getting back to you.  From an efficiency standpoint, you would want to wait until you're finishing the survey, but there wouldn't be any harm in just calling the update on each page save.

The code above will update the SurveyID column in the Work-related Injury or Illness Report list to the value of the JavaScript variable ID where the ID is equal to the value of the JavaScript variable Incident_x0200_Report.  If that's your goal, then you ought to be just about there.

M.

Dec 9, 2009 at 2:37 PM

Marc,

I managed to destroy the list I was trying to write to with this. Had to rebuild. Now that it's reinstated, I need to return to this.

Yes, what you stated is my goal... but it's not getting the data through.

I decided that it would make the most sense to add this to the NewForm, since that's also the place the jQuery is passing the List ID into the Survey data. And, since NewForm is only displayed this one time (then it goes to EditForm to complete the branching), it would be more logical to do it here.

So, all that said, here's the code I have in a CEWP on the Survey's NewForm:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script> 
<script src="/js/jquery.SPServices-0.4.5.min.js" type="text/javascript"></script> 
<script type="text/javascript">
  $(function() {
    $("input[value='Save']").hide();
    var rpt = $('select[name*=Lookup]');
    rpt.hide();
    fillDefaultValues("Lookup","ReportID");
    rpt.after($('select[name*=Lookup] option:selected').text());

  });
 $().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Work-related Injury/Illness Report",
   updates: "<Batch OnError='Continue'/>" +
     "<Method ID='1' Cmd='Update'>" +
      "<Field Name='ID'>" + Incident_x0200_Report + "</Field>" +
      "<Field Name='SurveyID'>" + ID + "</Field>" +
     "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
    alert("Hopefully, the SurveyID got written to the right List Item");
   }
  });

function fillDefaultValues(fieldName,value) {
  JSRequest.EnsureSetup();
  var qs = JSRequest.QueryString[value];
  var x = $('select[name*="'+fieldName+'"]');
  if (typeof(qs)=="undefined") {x.val(0)}
  else {x.val(qs)};
  x.change(function () {
    x.val(qs);
  })
  .change();
}

</script>

What am I missing?

Blessings,
Jim Bob

 

Coordinator
Dec 9, 2009 at 6:27 PM

If I'm following things right, then this won't work on NewForm.  At that point, there's no ID for the survey yet; the ID isn't created until you commit the item.  (Thus my fun $().SPServices.SPRedirectWithID function.)

Also, in the UpdateListItems call, it's not clear to me where the values for Incident_x0200_Report and ID would be coming from.

Finally, please upgrade to v0.4.6 of the library has it has some significant efficiency improvements.

M.

Dec 9, 2009 at 7:06 PM
Edited Dec 9, 2009 at 7:19 PM

Hmmm... actually have v0.4.6, so the fact I was trying to call v0.4.5 could be part of the problem, but...

Incident_x0200_Report is a Lookup column on the Survey. It holds the ID of the Incident Report, which was passed in via a link from an email. The link looks like this: http://site/subsite/Lists/Bloodborne%20Pathogen%20Survey/NewForm.aspx?ReportID=1. ReportID gets stored in Incident_x0200_Report by jQuery.

ID is the ID column of the Survey, whose EditForm (good point on the NewForm) I'm calling this from.

Is that syntax right?

Will the SPRedirectWithID work for a Survey's NewForm, too?

Blessings,
Jim Bob

Dec 9, 2009 at 7:19 PM
Edited Dec 9, 2009 at 7:33 PM

I just noticed that you said the name HERE:

"<Field Name='ID'>" + [HERE] + "</Field>"

...is a JavaScript variable. So, I need to set those from a jQuery selector, right?

Which also means that the Incident_x0200_Report field needs to be on the EditForm, too, right? Or will it automatically be on a Survey? IOW, are all of the fields that show up in the Survey available from EditForm at any time?

Blessings,
Jim Bob

Coordinator
Dec 9, 2009 at 7:31 PM

In order to use the values in controls on the page, you'll need to grab them with jQuery; they won't be defined otherwise.  So something like $().find("select:[Title='Incident Report']").val()

M.

Dec 9, 2009 at 7:35 PM

Cool. Figured that one out... how can I get the ID for the current record?

Blessings,
Jim Bob

Coordinator
Dec 9, 2009 at 7:36 PM

It you're in the EditForm, then you can grab it from the Query String.  I think it is also a few places in the DOM, but the Query String would be easiest.

M.

Dec 10, 2009 at 12:22 PM
Edited Dec 10, 2009 at 1:06 PM

Inch by inch... I have the variables getting the right data, but it's not getting written to the list item.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script> 
<script src="/js/jquery.SPServices-0.4.6.min.js" type="text/javascript"></script> 
<script type="text/javascript">

  $(function() {
    $("input[value='Save']").hide();    

    var ReportID = $("select[title='Incident Report']").val();
    var SurveyID = getQuerystring('ID');

 $().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Work-related Injury/Illness Report",
   updates: "<Batch OnError='Continue'/>" +
     "<Method ID='1' Cmd='Update'>" +
      "<Field Name='ID'>" + ReportID + "</Field>" +
      "<Field Name='SurveyID'>" + SurveyID + "</Field>" +
     "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
    alert(Status);
   }
  });
     
});

function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

</script>

When I do the above, I get an alert that shows the Status = 'error' and the list item no updatey. Seems like it's so close...

Blessings,
Jim Bob

Coordinator
Dec 10, 2009 at 1:02 PM

I think you need to wrap things in $(document).ready(function().  My guess is that things are firing too early. So:

$(document).ready(function() {
    $("input[value='Save']").hide();   

    var ReportID = $("select[title='Incident Report']").val();
    var SurveyID = getQuerystring('ID');

$().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Work-related Injury/Illness Report",
   updates: "<Batch OnError='Continue'/>" +
     "<Method ID='1' Cmd='Update'>" +
      "<Field Name='ID'>" + ReportID + "</Field>" +
      "<Field Name='SurveyID'>" + SurveyID + "</Field>" +
     "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
    alert(Status);
   }
  });
    
});

M.

Dec 10, 2009 at 1:13 PM

And yet, still no workie...

Blessings,
Jim Bob

Coordinator
Dec 10, 2009 at 1:24 PM

Toss in some more alerts, as below.  Do you have the ReportID and the SurveyID reversed in your call to UpdateListItems?  You're on the EditForm, right?

$(document).ready(function() {
    $("input[value='Save']").hide();   

    var ReportID = $("select[title='Incident Report']").val();
    var SurveyID = getQuerystring('ID');
  alert("ReportID="+ ReportID + " SurveyID=" + SurveyID);

$().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Work-related Injury/Illness Report",
   updates: "<Batch OnError='Continue'/>" +
     "<Method ID='1' Cmd='Update'>" +
      "<Field Name='ID'>" + ReportID + "</Field>" +
      "<Field Name='SurveyID'>" + SurveyID + "</Field>" +
     "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
    alert(xData.responseXML.xml);
    alert(Status);
   }
  });
    
});

M.

Dec 10, 2009 at 1:40 PM

Did exactly that.

First alert displayed: ReportID=1 SurveyID=33 (both of which are right)

Second alert displayed nothing.

And yes, I'm on the EditForm. ;)

I don't think I have them reversed. I want to write to the "Work-related Injury/Illness Report" (does this need to be the Display Name or its internal name?). In that list, I want to update the record with ID = ReportID, setting its SurveyID to the SurveyID I'm passing in.

Blessings,
Jim Bob

Coordinator
Dec 10, 2009 at 2:01 PM

Hmm.  Second alert displaying nothing doesn't make sense.  It ought to at least show you undefined or something.

Is "Work-related Injury/Illness Report" a Document Library or a list?  If it is a Document Library, then you also need to specify the FileRef in the UpdateListItems call for it to work.  (This doesn't make sense to me, but it is true.)

M.

Dec 10, 2009 at 2:49 PM

It's a list.

Blessings,
Jim Bob

Coordinator
Dec 10, 2009 at 2:59 PM

I'm going to need the blessings if this keeps going.  ;+)

Let's try this:

$(document).ready(function() {
    $("input[value='Save']").hide();   

    var ReportID = $("select[title='Incident Report']").val();
    var SurveyID = getQuerystring('ID');
  alert("ReportID="+ ReportID + " SurveyID=" + SurveyID);

$().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Work-related Injury/Illness Report",
   updates: "<Batch OnError='Continue'/>" +
     "<Method ID='1' Cmd='Update'>" +
      "<Field Name='ID'>" + ReportID + "</Field>" +
      "<Field Name='SurveyID'>" + SurveyID + "</Field>" +
     "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
    alert("XML response:" + xData.responseXML.xml);
    alert(Status);
   }
  });
    
});

Dec 10, 2009 at 3:03 PM

You and me both! ;)

Second alert: "XML response:"

Blessings (and THANKS for spending so much energy on this),
Jim Bob

Dec 10, 2009 at 5:39 PM
Edited Dec 10, 2009 at 6:01 PM

Doh!!! Found it...

$().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Work-related Injury/Illness Report",
   updates: "<Batch OnError='Continue'/>" +
     "<Method ID='1' Cmd='Update'>" +
      "<Field Name='SurveyID'>" + SurveyID + "</Field>" +
      "<Field Name='ID'>" + ReportID + "</Field>" +
      "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
    alert("XML response:" + xData.responseXML.xml);
   }
  });
    
});

Took out the tag closer on the Batch tag, and put the target list ID last in the list. Works like a charm now! ;)

Thanks!!!

Blessings,
Jim Bob

 

Dec 10, 2009 at 6:16 PM

Well... almost a charm. Looks like I'll need to add your SPRedirectWithID to the NewForm, since the ReportID is only there on the first page.

But, still... great progress. Thanks a ton.

Will be writing this up to post on EUSP, giving you credit all over the place! :)

Blessings,
Jim Bob

Coordinator
Dec 10, 2009 at 6:19 PM
Edited Dec 10, 2009 at 6:19 PM

DOH is right. One of those things that you can't see even if you're staring at it (as both of us proved).  The ID can be any place in the order, but the batch close tag would do it.  It was doing exactly what you were asking: nothing!

Glad it's working.  Let me know if this little debacle gives you any ideas about how I can improve things.

M.

Dec 10, 2009 at 6:32 PM

Hmm... can't do the SPRedirectWithID on NewForm, because there's a required field there that won't let it save and load the EditForm...

I need to get the ReportID onto the "second" page of the EditForm, somehow. Thinking...

Blessings,
Jim Bob

Dec 11, 2009 at 1:01 PM

Here's what I'm thinking...

To get the Incident Report ID (Incident_x0200_Report on the Bloodborne Pathogen Survey) on any iteration of EditForm, I could use GetListItems to look up the survey item I'm on to get the report ID.

$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Bloodborne Pathogen Survey",
    CAMLQuery: "<Query><Where><Eq>" +
                    "<FieldRef Name='ID' />" +
                    "<Value Type='Integer'>" + SurveyID + "</Value>" +
                "</Eq></Where></Query>",
    completefunc: function(xData, Status) {
        alert(xData.responseXML.xml);
    }
});

Where I'm stuck now, is getting the attribute out of the XML. I'm sure it's something easy, but it's just not coming through.

Blessings,
Jim Bob

Coordinator
Dec 11, 2009 at 1:19 PM

You may be running into variable scoping issues, We can assume you will be getting one item back from your query, correct? In the completefunc, you'll want to do something like this:

var ReportID = null;
$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Bloodborne Pathogen Survey",
    CAMLQuery: "<Query><Where><Eq>" +
                    "<FieldRef Name='ID' />" +
                    "<Value Type='Integer'>" + SurveyID + "</Value>" +
                "</Eq></Where></Query>",
    completefunc: function(xData, Status) {
        alert(xData.responseXML.xml);
        $(xData.responseXML).find("[nodeName=z:row]").each(function() {
      ReportId = $(this).attr("ows_Incident_x0200_Report"); // StaticNames are limited to 20 chars, I think. Check the xData.responseXML.xml in the alert to see what the right value is.
     });
} });

M.

Dec 11, 2009 at 1:58 PM

Dang it... I keep getting so close. So, here's the thing:

When a branching survey is created—even though it starts with NewForm, "saves" and then goes on to EditForm—doesn't actually save to the list on "Next." So, GetListItems' responseXML doesn't contain that data in that column yet.

How else could I get the ReportID over to EditForm, so that I have both the SurveyID and the ReportID to work with? I'm passing it to NewForm via the querystring. But, it's not there when I "Next" to the EditForm.

Blessings,

JIm Bob

Coordinator
Dec 11, 2009 at 2:41 PM

Can you paste the URL as it arrives at the NewForm, and then the URL as it arrives at the first Editform?

M.

Dec 11, 2009 at 2:44 PM

Sure. Here ya go...

NewForm: http://sitepath/Lists/Bloodborne%20Pathogen%20Survey/NewForm.aspx?ReportID=1

EditForm: http://sitepath/Lists/Bloodborne%20Pathogen%20Survey/EditForm.aspx?ID=41&FirstField=Device_x0020_type_x003a_

Blessings,
Jim Bob

Coordinator
Dec 11, 2009 at 2:56 PM

The trick I use in SPRedirectWithID is to change the form action.  You probably could do the same thing here to add the ReportID to the action.  It feels a little "hack-like", but some would say that all of this jQuery stuff is a hack.  If it works, then it's a good hack, IMHO!

M.

Dec 11, 2009 at 4:13 PM

OK. I'm tracking with you here, but not having any success doing it... How do I go about changing the form action?

Blessings,
Jim Bob

Coordinator
Dec 11, 2009 at 4:20 PM

If you look at the code in the library for SPRedirectWithID, you'll see this section (which I may need to clean up a little now that I'm looking at it!):

$().find("form[name='aspnetForm']").each(function() {
    // This page...
    var thisUrl = (location.href.indexOf("?") > 0) ? location.href.substring(0, location.href.indexOf("?")) : location.href;
    // ... plus the Source if it exists
    var thisSource = (typeof vals["Source"] == "string") ?
     "Source=" + vals["Source"].replace(/\//g, "%2f").replace(/:/g, "%3a") : "";
    var newAction = thisUrl + "?Source=" + thisUrl + "?ID=" + lastID +
     ((thisSource.length > 0) ? ("%26RealSource=" + vals["Source"]) : "") +
     ((typeof vals["RedirectURL"] == "string") ? ("%26RedirectURL=" + vals["RedirectURL"]) : "");
    $(this).attr("action", newAction);
   });

You could do something like this:

$().find("form[name='aspnetForm']").attr("action", $(this).attr("action") + "&ReportID=1");

M.

Dec 11, 2009 at 5:00 PM

Where do I put that?

JB

Coordinator
Dec 11, 2009 at 5:17 PM
Edited Dec 13, 2009 at 5:03 AM

:+)  You'll need to play around with it a bit, but I just put this into a page and the basics are there:

$(document).ready(function() {
   var newAction = $().find("form[name='aspnetForm']").attr("action") + "&ReportID=1";
   alert($().find("form[name='aspnetForm']").attr("action"));
   $().find("form[name='aspnetForm']").attr("action", newAction);
   alert($().find("form[name='aspnetForm']").attr("action"));
});

You'd put this (well, this without the alerts) into the NewForm.  You'd want to grab the ReportID off the current Query String and put it into the form action, something like above.  Basically, the form action is where the user goes when they submit the form.

M. 

Dec 11, 2009 at 5:59 PM
Edited Dec 11, 2009 at 6:48 PM

Well, good. That's what I thought... and where I put it... but it's not paying forward to EditForm on "Next."

The action on NewForm is NewForm; appears to add &Report=1 to action, but redirect happens separately..

JB

Coordinator
Dec 11, 2009 at 6:09 PM
I'm tied up the rest of the afternoon, but I'll try to take another
look at it tonight for you.

M.
>
Dec 14, 2009 at 4:06 PM

OK, Marc. Coffee's beginning to reach extremities. ;)

Still wondering how to:

  • get ReportID (from NewForm.aspx QS) to pay forward to EditForm.aspx, so I have it once survey ID is created; or
  • get NextItem button to also SaveItem, so that I can use GetListItems to pull in ReportID from responseXML; or
  • get SaveItem button to move forward to second page of EditForm.aspx from NewForm.aspx, so I can do (b); or
  • get EditForm.aspx to reload from page one (where ReportID is in the form data), AFTER the Finish button is so the CEWP can save back to the Report; or
  • some other untried/unconsidered option that will allow the ID of the survey to be saved in the item record that spawned the request for the Survey.

Just so you know, if I re-edit the survey (after it has been Finished), the original code we worked out writes back to the report just fine, because (a) the Survey ID exists, and (b) the ReportID is accessible from page 1 of the EditForm.aspx.

Blessings,
Jim Bob

Coordinator
Dec 14, 2009 at 5:28 PM

Jim Bob:

I'm just playing around with a survey, and it's sort of annoying how it won't play by the same rules as most pages with the Query String. I'm not sure what the best approach for this is going to turn out to be.  I wonder if an adapted SPRedirectWithID might work.

M.

Dec 14, 2009 at 5:32 PM

Marc,

Good, so it's not just me. ;) Perhaps your idea might work. It would require a "Save" on NewForm.aspx, with a return to EditForm.aspx, but...

The reason it didn't work the first time is that one of the fields is required, so it couldn't save it without an answer. But, in fact, I wonder how the Save would behave for a survey that doesn't have all of the required fields (in all branches). I have a tweet out to MSFT, hoping someone can help 'splain an option. Thanks.

Blessings,
Jim Bob

Coordinator
Dec 14, 2009 at 5:35 PM

In my little test survey, after I make my choice on the first question, the next page is EditForm.aspx with the ID specified, so the item has been saved.  What's your survey doing on NewForm.aspx? 

M.

Dec 14, 2009 at 6:02 PM

Mine does that, too.

But, on NewForm.aspx I have access to the ReportID from the querystring. On the next page (EditForm.aspx with the survey ID specified in the querystring), I no longer have access ReportID, even though I can now get to "SurveyID."

When I use GetListItems, ReportID is not included in the responseXML.

<?xml version="1.0"?> 
<soap:Envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd= "http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetListltemsResponse xmlns= "http://schemas.microsoft.com/sharepoint/soap/"> <GetListItemsResult> <listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> <rs:data ItemCount="1"> <z:row ows_Level= "255" ows_Uniqueld= "47;#{A05222BE-7A22-4F49-91C8-591F064F4C9C}" ows-FSObjType= "47;#0"
ows_Nature_x0020_of_x0020_exposure_x="Needlestick/sharps accident" ows_Metalnfo= "47;#" ows_ID="47"
ows_owshiddenversion="2" ows_Created="2009-12-11 14:19:02"
ows_FileRef="47:#HR/WorkSafetyHealth/Lists/Bloodborne Pathogen Survey/47_.000" ows_ModerationStatus="0"/> </rs:data> </Iistitems> </GetListltemsResult> </GetListltemsResponse> </soap:Body> </soap:Envelope>

The correct ReportID should be 1. Strange, though, that the Nature_x0020_of_x0020_exposure_x column is returned here, but not the ReportID.

And, moving forward, the next columns are stored, too. Why not the Lookup column? Hmm...

Anything ring bell there?

Blessings,
Jim Bob

Coordinator
Dec 14, 2009 at 6:09 PM

The ReportID on the Query String won't be saved anywhere unless *you* save it.  What you are seeing with GetListItems above is what has been saved to the survey item so far.  Other columns will be added as you go through the branching logic.

My thought is to adapt SPRedirectWithID so that when you're returned back to the page and the ID for the new item has been determined (this would be just before line 1450 in v0.4.7), you could do a UpdateListItems to write the ReportID into the survey item before SharePpoint moves on and you've lost the ReportID.

M.

Dec 14, 2009 at 6:16 PM
Edited Dec 14, 2009 at 6:31 PM

I do save it though.

The link comes in like this: .../NewForm.aspx?ReportID=1

I have jQuery in a CEWP to pull the ReportID into the page:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script> 
<script src="/js/jquery.SPServices-0.4.5.min.js" type="text/javascript"></script> 
<script type="text/javascript">
  $(document).ready(function() {
    $("input[value='Save']").hide();
    $("table.ms-formtoolbar tr:first").hide();
    var rpt = $('select[name*=Lookup]');
    rpt.hide();
    fillDefaultValues("Lookup","ReportID");
    var rptText = $('select[name*=Lookup] option:selected').text();
    var ReportID = $('select[name*=Lookup] option:selected').val();
    rpt.after(rptText);
    var redirTxt = "&ReportID=" + ReportID;
    
  });

function fillDefaultValues(fieldName,value) {
  JSRequest.EnsureSetup();
  var qs = JSRequest.QueryString[value];
  var x = $('select[name*="'+fieldName+'"]');
  if (typeof(qs)=="undefined") {x.val(0)}
  else {x.val(qs)};
  x.change(function () {
    x.val(qs);
  })
  .change();
}

</script>

Am I missing something there? I didn't think so because if I leave this page and come back to it through EditForm.aspx, it shows the correct information.
(And an alert shows the correct data. And it shows up in the responseXML from then on.)

Blessings,
Jim Bob

Coordinator
Dec 14, 2009 at 6:34 PM

Ok, I'm getting a little lost.  (Weekend brain, I guess.)

  • So, you pass ReportID on the Query string into NewForm.aspx
  • On NewForm.aspx, you have the script directly above which populates a select (dropdown) control called Lookup with the value of ReportID.
  • Then when you click Next, the item is saved, and you're redirected to EditForm.aspx.
  • At this point, ReportID is *not* in the item when you check it with GetListItems

Am I getting it right?

M.

Dec 14, 2009 at 6:40 PM

Yes, you have it exactly right.

...just had another thought. I'm going to test the following.

  • Create another column (question) that is: a single line of text; and optional, and
  • Put it in the first branch. Then,
  • Hide it with jQuery, and
  • Put the ReportID in it, then
  • See if that column comes back in the responseXML

Lord, please let this work!

Blessings,
Jim Bob

Coordinator
Dec 14, 2009 at 6:42 PM

Well, that was my next question.  What Lookup was, how you had it defined, etc.

M.

Dec 14, 2009 at 7:21 PM

Well, Lookup in this context is just the jQuery I used to find the form field in the HTML. Its name contains "Lookup" and is the only one of its kind on the page.

I changed the 3rd line in fillDefaultValues from:

var x = $('select[name*="'+fieldName+'"]');

to:

var x = $('select[title="'+fieldName+'"]');

...and passed it "Incident Report" instead. The select still works.

I added the new column (StaticName/DisplayName = txtReportID) and used the same syntax find and hide it. Before I hid it, though, I made sure that it was getting the data into it.

But, it's not showing up in the responseXML either.

Going to test it to see what happens if I don't hide it.

Blessings,
Jim Bob

Dec 14, 2009 at 7:25 PM

...Not hiding it didn't help either.

So, question:

How could the content show up on the page, but not be in the XML when calling GetListItems?

Blessings,
Jim Bob

Coordinator
Dec 14, 2009 at 7:34 PM

Well, it must not be getting saved, right?  When you say it's showing up in the page, I think you said that you can go back to the form and see the value.  How are you doing that?

M.

Dec 14, 2009 at 7:54 PM

It most definitely is being saved. From the "Show all responses" list (.../Lists/Bloodborne%20Pathogen%20Survey/AllItems.aspx), clicking on the record to bring up DispForm.aspx, shows that both the Lookup and the String were saved to the Survey record.

Dude! I'm baffled. You?

Blessings,
Jim Bob

Coordinator
Dec 14, 2009 at 7:56 PM

Yup.  Based on everything you're telling me, there's something inconsistent going on.  Or we're both missing something.

Can you paste the call to GetListItems you're using?

M.

Dec 14, 2009 at 8:02 PM

Sure, here you go:

$().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "Bloodborne Pathogen Survey",
	CAMLQuery: "<Query>" +
		"<Where>" +
		    "<Eq>" +
			"<FieldRef Name='ID' />" +
			"<Value Type='Integer'>" + SurveyID + "</Value>" +
		    "</Eq>" +
		"</Where>" +
	    "</Query>",
        CAMLViewFields: "<ViewFields><FieldRef Name='Incident_x0200_Report' /></ViewFields>",
            completefunc: function(xData, Status) {
                alert(xData.responseXML.xml);
                $(xData.responseXML).find("[nodeName=z:row]").each(function() {
                   ReportId = $(this).attr("ows_txtReportID");
                });
                alert("GetListItems -> ReportID="+ ReportID + " SurveyID=" + SurveyID);
            }
});

Another strange bit: All of the other text fields show up in the XML. I'm displaying it in an alert, and every time the EditForm.aspx loads with the next branch, the XML gets long. The only difference at this point, between the ones that have saved and the ones that haven't is that the ones that work are all required, and my test txtReportID isn't. Going to try making it required and test again.

Blessings,
Jim Bob

Dec 14, 2009 at 8:05 PM

OK. Here's some silliness:

I removed the CAMLViewFields and both of them showed up in the XML. Your thoughts?

Blessings,
Jim Bob

Coordinator
Dec 14, 2009 at 8:20 PM

Ok, now that's making sense.  Specifying ViewFields will show *only* the columns you have specified, plus a set of core columns you can't turn off.  So by specifying "<ViewFields><FieldRef Name='Incident_x0200_Report' /></ViewFields>", you were essentially ensuring that you wouldn't see all of the available values.

So it looks like the ReportID is indeed being saved, and you're good to go, right?

M.

Dec 14, 2009 at 8:22 PM

Yes, I think it's working now. Whew! Will test more tomorrow. Thanks for sticking with me through all of that. Sheesh! :)

Blessings,
Jim Bob

Coordinator
Dec 14, 2009 at 8:27 PM

No worries.  Hopefully you're learning things along the way.  I always do!

M.

Dec 15, 2009 at 2:18 PM

I've learned tons! :)

Thank you, sir!

Blessings,
Jim Bob

PS: I'm writing up the solution for EUSP and will post a link to it here.

Jan 11, 2010 at 7:04 PM

Here's the article on EndUserSharePoint:

Blessings,
Jim Bob

Coordinator
Jan 11, 2010 at 7:08 PM

Thanks for closing the loop!

M.