Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint 2007 AddList and AddListFromFeature are missing template columns and data content

What I've Done

  • Inside SharePoint I created a List based on the Project Tasks template
  • I deleted most default columns, and added new custom columns
  • I added data using the new format
  • Then I did a "Save as template" and chose to save the template with the content

What IS Working

Now, when I use that template to create a new List inside of SharePoint it works perfectly. The custom columns are present, and the data is all pre-filled as expected.

What ISN'T Working

However, when I use the AddList or AddListFromFeature methods made available by SharePoint web services the new list is created, but it is simply based off of the original Project Tasks template with the default columns and no data!

What I've Tried

  • I tried following the suggestion in the article from Phase 2 to setup a custom template ID, but that only prevented me from using the template at all (was no longer listed when I do a "Create").
  • I'm still trying to figure out if this article applies - it seems to be a similar issue, but applied to Sites instead of Lists.
  • I found that another person was having the same problem about a year ago.

System Setup

Working with SharePoint 2007 (I think?), using PHP with NuSOAP to connect. The connection is definitely working as I've added items to lists, created lists, and read data.

Code Samples

Request - against Phase 2 Method template above

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2034="http://tempuri.org"><SOAP-ENV:Body>
<AddListFromFeature xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <listName>2Test Milestone Release</listName>
    <description>Testing this out</description>
    <featureID>{00BFEA71-513D-4CA0-96C2-6A47775C0119}</featureID>
    <templateID>151</templateID>
</AddListFromFeature></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response - fails due to templateID not being recognized

<?xml version="1.0" encoding="utf-8"?><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><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring><detail><errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Cannot complete this action.

Please try again.</errorstring><errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x81072101</errorcode></detail></soap:Fault></soap:Body></soap:Envelope>

I'm stumped! So if you can help - I'd be a very happy person! Thanks, in advance!

like image 618
Joshua Avatar asked Nov 15 '22 15:11

Joshua


1 Answers

I would chase why you can't create the list via the interface in the first place, these two web service calls don't seem to include the important parameter when creating from custom templates, lets analyse the querystrings:

New Project Tasks (out of the box)

http://site/_layouts/new.aspx?FeatureId={00bfea71-513d-4ca0-96c2-6a47775c0119}&ListTemplate=150

New Project Tasks Custom (saved in the list template gallery)

http://site/_layouts/new.aspx?CustomTemplate=PT6.stp&FeatureId={00bfea71-513d-4ca0-96c2-6a47775c0119}&ListTemplate=150

New Project Tasks Custom (manifest.xml edited to 151)

http://site/_layouts/new.aspx?CustomTemplate=PT6.stp&FeatureId={00bfea71-513d-4ca0-96c2-6a47775c0119}&ListTemplate=151

They all work, so my take here is that the Web Service is a no no for custom templates, or it has some secret magic (common in list definitions) since specifying only the ListTemplate without being explicitly CUSTOM won't work even in the UI.

If you can't get around with this apparent limitation, my suggestions are:

  1. .NET, note that this post has some voodoo in the first comment if you happen to get the same error
  2. Make an IFRAME with http://site/_layouts/new.aspx?CustomTemplate=PT6.stp&FeatureId={00bfea71-513d-4ca0-96c2-6a47775c0119}&ListTemplate=150 as source and fill the fields using javascript, and then trigger the OK button click, make some full page loading transition and it will even look good.

Method 2 needs to be done from the same domain, if you are not running your PHP from the same domain (unlikely) you need to create a page inside the SharePoint site to contain this hack, it can be as simple as a Web Part Page with a Content Editor Web Part in it, you read some querystring parameters, place them on the fields, trigger the OK and wait for the page to change so you can redirect to a "success" page.

Edit: I got curious and looked at the source of New.aspx, it has this little snippet (bIsCustomTemplate = strCustomTemplate != null, strCustomTemplate = querystring "CustomTemplate"):

<% if (bIsCustomTemplate) { %>
<input id="onetidCustomTemplate" type="Hidden" name="CustomTemplate" value=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(strCustomTemplate),Response.Output);%> />
<% } %>

I looked at the disassembled code but I don't think we can post it here, but it only proves that the UI builds it from a post (Request.Form) and looks for the CustomTemplate parameter, and the Web Service has only those methods were you can't specify a custom template.

like image 155
Francisco Aquino Avatar answered Dec 27 '22 04:12

Francisco Aquino