Daryl Rasmussen's Not-so-random Thoughts about SharePoint Here in my world

Archive for February, 2015

Create List Instance without List Definition

This worked (mostly):

http://blogs.msdn.com/b/saurabh1/archive/2011/11/26/creating-list-instance-schema-in-sharepoint-2010.aspx

But:  in SP Here at my client’s office, I had to muck about with the Target location (step 6) for the Schema.xml file.   I ended up setting it to the name of the visual studio project, not the name of the list contained there-in.  Also in step 6, file I edited was SharePointProjectItem.spdata, not SharePointItem.data.

Finally, I had to rename the .stp to a .cab not a .zip before I could open the manifest.

In case the link above ever breaks (and also so I have the instructions handy for myself in future), here’s the content of it, replicated for posterity.  Credit is hereby given to the original author, Saurabh Khatri, for a great time saving idea.

Assumtions: I am assuming that we have already created SharePoint Project in Visual Studio 2010.

Preparing Solution Structure

1. In your visual studio instance, Right Click on your sharepoint project and click on Add > New Item.
2. From the Wizard, choose the SharePoint List Instance.
3. a) Give some name your List Instance(Display Name), I will give this ‘MyNewCustomList’
b) Choose a List Template, You can choose any List Template, and choose a List Instance, Let me choose Custom List to keep it simple.
c) Give List a URL, “Lists\MyNewCustomList”
d) Click ok to close the wizard.
4. After step 3, we will be having a SharePointItem  ‘MyNewCustomList’ of type List Instance with a element.xml file, instantiating it from TemplateType=100, that will create a custom list with a Title Column in it. But we wanted to add the fields to this custom schema.(In SharePoint 2010 we can create a List Instance without creating a ListTemplate by specifying CustomSchema property for ListInstance. http://msdn.microsoft.com/en-us/library/ms476062.aspx

<ListInstance Title=”MyNewCustomList” OnQuickLaunch=”TRUE” TemplateType=”100″ Url=”Lists/MyNewCustomList” Description=”My List Instance” CustomSchema=”MyNewCustomList\Schema.xml” />

5. Now Lets Add a Schema.xml File to your SharePointItem.
6. Also include this file into your SharePointItem.data file.
This is how we do it. Click on the your ‘MyNewCustomList’ in Solution Explorer in Visual Studio. Right click Open Folder in Windows Explorer. Open SharePointItem.Data in notepad

<ProjectItemFile Source=”Schema.xml” Target=”MyNewCustomList\” Type=”ElementFile” />

We are done with Solution Preparation steps.

We will now create a Custom List in SharePoint with ”MyNewCustomList”. Go to List Settings and Add the columns, as per the requirement. After doing with all changes whether it is a addition of List Column, Creating a View, addition of some content Type etc.

1. Save this list as Template. Go to Template Gallery, and Download your list template. This file will be a .stp file.\
2. Change the File Extenstion to .zip.
3. Open the zip file, it will contain a manifest.xml
4. Open Manifest.xml file in some nice editor like notepad++.
5. Carefully, Locate node “<List>” in this xml. Copy this entire section of <List>…</List> and now paste it in your schema.xml file we created in above steps.

Few Final Modifications and we are done in Schema.xml file.

1. Remove the name attribute containing List GUID of your previous List.

<List Name=”SomeGUid” …> remove this Name attribute, we don’t need this in our schema

2.Replace the following  nodes <View>

<View BaseViewID=”1″ Type=”HTML” Level=”1″ ContentTypeID=”0x” WebPartZoneID=”Main” OrderedView=”TRUE” DisplayName=”All Links” DefaultView=”TRUE” MobileView=”TRUE” MobileDefaultView=”TRUE” SetupPath=”pages\viewpage.aspx” ImageUrl=”/_layouts/images/links.png” Url=”AllItems.aspx”>

Also replace the Forms Node with the below one.

<Forms>

<Form Type=”DisplayForm” Url=”DispForm.aspx” SetupPath=”pages\form.aspx” WebPartZoneID=”Main” />
<Form Type=”EditForm” Url=”EditForm.aspx” SetupPath=”pages\form.aspx” WebPartZoneID=”Main” />
<Form Type=”NewForm” Url=”NewForm.aspx” SetupPath=”pages\form.aspx” WebPartZoneID=”Main” />

</Forms>

Great we are done, Now we can include this ListInstance in a feature and create a package. Activating that feature will create a ListInstance.

The first client I used this technique at was on SharePoint 2010.  It worked as well for me in SharePoint 2013 at the next client as well.

Advertisements

Coding External Content Types

I was trying to follow the example given here:

http://www.sharemuch.com/2010/01/29/using-sharepoint-2010-external-lists-programmatically/

However, it didn’t work for me. This link looked slightly more promising:

http://www.sharemuch.com/2010/05/03/creating-sharepoint-2010-bdc-list-instances-in-programmatically/

But I still was having trouble figuring out in SP Here whether the “External System” shown in Central Admin on the Manage BDC Services page was the LOB Name, or the LOB instance name, or the Model Name, and therefore, confused about what to put in the properties in our specific instance in order to get the Holiday list working from a client’s Dynamics (DAX) based database on the above examples.

To make matters worse, both of the above links, and the post here

http://pholpar.wordpress.com/2010/08/23/creating-external-lists-from-code/

say that the format for the EntityNamespace property is supposed to have “dot” notation.

Trial and error and a bit of dogged persistence, and I finally figured it out on my own. The final post above needs 1 correction to make it work (I replied to the author’s post on-line in 2012 when I encountered the issue, but as of Feb 2015, my comments are still not visible there). It took me a few hours to figure this out, but the fact that the documentation here does not mention any prefix or dot-notation should have been my first clue. Basically, you need to change

listDataSource.SetProperty(SPListDataSource.BDCProperties.EntityNamespace, “YourBdc.EntityNamespace”);

To

listDataSource.SetProperty(SPListDataSource.BDCProperties.EntityNamespace, “EntityNamespace”);

In other words do not prefix the EntityNamespace with “YourBdc.”, or you will get an error that says: Entity (external Content Type) cannot be found with Namespace= “YourBdc.EntityNamespace” , Name = “YourBdcEntity” The error is thrown on the call to list.Add.

Why the “Next” Button Doesn’t Work for Me in SharePoint 2010 Surveys

Recently I was helping a client put together a survey in SharePoint 2010, showing them all the various types of questions, and things you can do with them.  They were having a hard time visualizing it, so I ended up building their survey for them so they could see the overall effects in their desired question set.  About 65 questions in all, and to my dismay the “Next” button (which shows up at the top and bottom of the form if you have either a Page Separator field or if you implement branching logic in your questions) wasn’t working.

The first “page” of the survey would load, but when the “Next” button was clicked, that page would just re-load.  It would NOT move on to the next “page” (after the Page Separator or branch).  I searched everywhere on the internet for a possible reason.  Nada.  Nothing.  I can’t believe I’m the only person who ever encountered this.  And I certainly can’t show it to the client in this state.  WTF?

I thought maybe the client had re-ordered the questions in the branching logic, resulting in some kind of circular reference.  I painstakingly went through every question (hint – click the “Change the order of the questions” link from the Survey Settings page to see a summary of what is branching where).  No luck.  Everything seemed fine.

I then thought perhaps the use of special characters like quotes and apostrophes in the question title were mucking things up.  So I removed all of them (Changing questions like “Please enter any comments regarding the president’s address” to something like “Please enter any comments regarding the presidential address”).  No joy.  Still it would not leave page 1.

Then I thought maybe my survey list was corrupt.  Hey, lets face it.  Sometimes that happens with SharePoint.

So I rebuilt it (all 65 questions of it!) from scratch, stopping after every page separator question was added, and after every branch section was set up to test the new survey.  63 questions in, and everything is looking good.

The answer came when I added my 64th question (which was a plain text field for people to enter their phone number if they wanted to be contacted regarding their submission).  The fly in the ointment was that it was using the column validation capabilities of SharePoint to ensure the phone number was entered in a standard format.

The field was called “Optional – Phone” and had the following Column Validation formula:

=AND(LEN([Optional – Phone])=14,IF(ISERROR(FIND(“(“,[Optional – Phone],1)),FALSE,(FIND(“(“,[Optional – Phone])=1)),IF(ISERROR(FIND(“)”,[Optional – Phone],5)),FALSE,(FIND(“)”,[Optional – Phone],5)=5)),IF(ISERROR(FIND(” “,[Optional – Phone],6)),FALSE,(FIND(” “,[Optional – Phone],6)=6)),IF(ISERROR(FIND(“-“,[Optional – Phone],10)),FALSE,(FIND(“-“,[Optional – Phone],10)=10)),IF(ISERROR(1*CONCATENATE(MID([Optional – Phone],2,3),MID([Optional – Phone],7,3),MID([Optional – Phone],11,4))),FALSE,AND(1*CONCATENATE(MID([Optional – Phone],2,3),MID([Optional – Phone],7,3),MID([Optional – Phone],11,4))>1000000000,1*MID([Optional – Phone],2,3)<>911,1*MID([Optional – Phone],7,3)<>911,1*MID([Optional – Phone],7,3)<>555)))

It also had the following User Message:

Please enter the phone number in the format (###) ###-####

Do you see the problem?  I didn’t at first, but here’s what I now believe:

When the user is finished answering the questions on Page 1 and clicks next, the above validation rule fires, and fails.  The “Optional – Phone” field is on a different page that the user has not gotten to yet, so of course they haven’t filled the “Optional – Phone” field in yet.  And even though the field is not mandatory, the first part of the validation rule says that the length must be 14 characters.

The length at this point is still zero.  The User Message is probably being displayed under the “Optional – Phone” field, but since the field isn’t visible on the current page, the user gets no feedback and the “Next” button just reloads the current page.

Of course this is just a theory, because I can’t find anything in Microsoft’s documentation to say that this is what’s happening, however when I change the Column Validation formula to allow either zero or 14-character length strings, the problem goes away, so it seems a valid assumption.

For those who are interested, here’s the corrected formula:

=OR(LEN([Optional – Phone])=0, AND(LEN([Optional – Phone])=14,IF(ISERROR(FIND(“(“,[Optional – Phone],1)),FALSE,(FIND(“(“,[Optional – Phone])=1)),IF(ISERROR(FIND(“)”,[Optional – Phone],5)),FALSE,(FIND(“)”,[Optional – Phone],5)=5)),IF(ISERROR(FIND(” “,[Optional – Phone],6)),FALSE,(FIND(” “,[Optional – Phone],6)=6)),IF(ISERROR(FIND(“-“,[Optional – Phone],10)),FALSE,(FIND(“-“,[Optional – Phone],10)=10)),IF(ISERROR(1*CONCATENATE(MID([Optional – Phone],2,3),MID([Optional – Phone],7,3),MID([Optional – Phone],11,4))),FALSE,AND(1*CONCATENATE(MID([Optional – Phone],2,3),MID([Optional – Phone],7,3),MID([Optional – Phone],11,4))>1000000000,1*MID([Optional – Phone],2,3)<>911,1*MID([Optional – Phone],7,3)<>911,1*MID([Optional – Phone],7,3)<>555))))

After many days of cursing and frustration, the Survey is working again.

The moral of this story is  “Be careful with Column Validation in Survey Lists”.

That’s SP Here.  I would bet a case of doughnuts that the same is true in MOSS 2007, SP 2013, and O365.

Tag Cloud