Get query string value and write to list item?

Jan 6, 2012 at 8:58 PM

I'm using a script-based solution to add a Comment Box to dispform.aspx in a MOSS document library. The comments live in a separate list and I have a requirement to show the Name metadata from the document library in every item in the comments list. The only metadata passed from the library to the comments list is the URL of dispform.aspx, e.g. http://sitename/library/dispform.aspx?ID=1. Columns in the CommentBox list include basically Title (where the URL for the dispform.aspx page holding the comment is stored) and a text column.

If I could parse the ID value out of the URL string and write it to the list item in the CommentBox list (e.g. in an extra column called ParentID) then I'd have enough to use in a workflow so that I could fetch the Name metadata from the doc library. I've seen some script examples for extracting a value from a query string but I'm not enough of a developer to work out how to write those values to the CommentBox list. I'm also not sure where to place the script... the CommentBox script that actually creates and saves the comments runs on dispform.aspx in the document library. I almost wonder whether the only way to do this would be to modify the CommentBox script with either additional Javascript or SPServices calls, both likely beyond my meager skills.

SPServices to the rescue?

Jan 8, 2012 at 10:40 PM


SPServices can definitely help enable this. It's even possible to do the whole comment box with SPServices, but Alexander's solution is more elegant. (Maybe it should be something I add to SPservices!)

The function $().SPServices.SPGetQueryString allows you to get the values from the Query String. The call for what you want would be:

var queryStringVals = $().SPServices.SPGetQueryString();
var thisID = queryStringVals["ID"];

Then you can do whatever you want with thisID. It sounds like the best thing would be to have a hidden column in the Comment Box that you can populate with the ID to link the item from the DispForm to the item in the comments list.


Jan 18, 2012 at 10:01 PM

I did not notice that this function existed in SPS.  It will be very useful to me...I can replace the manual javascript parsing of querystring values in a filter-provider.  Thanks Again Marc!