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

Choosing a Content Type when using SPLookupAddNew

Oct 21, 2011 at 12:26 PM
Edited Oct 21, 2011 at 12:27 PM

I am fairly new to using jQuery/javascript and i'm am also new into SharePoint customization in so i'm not sure if i'm asking a question with an obvious answer.

I am using SPLookupAddNew and SPCascadeDropdowns in a list and both work just fine for me but i have a question about how i should tackle something particular I wish to accomplish.

I have a list named ClientContactConnections which i use to simulate a many-to-many relationship between clients and contacts. In that list i have created three lookup columns

  • One named "Client" which looks up the "Clients" list.
  • One named "Contact type" which looks op the "TypeOfContacts" list. 
  • One named "Contact" which looks up the "Contacts" list.  I'm using SPCascadeDropdowns for the selection of different type of contacts. Selecting a Contact type gives me different contact options than when using another Contact type.

A user can select a client. Afterwards, the user selects a contact type he want the client to make a connection with. Last, the contact is selected. Depending on the value of contact type the contacts column values are diplayed. I'm using SPCascadeDropdowns for that.

The "Contacts" list is a list which contains several Content Types. One for every type of contact (the CT's have the same names as the values in the TypeOfContacts list). That way users can easily add items according to wish since every contact type has diffent attributes. In addion, a hidden lookup column named "ContactType" is used in every content type. when a user adds an item, a workflow starts which detects the content type. It then provides the "ContactType" column with a value. Using this construction i can use it for SPCascadeDropdowns while using content types instead of a field choice for the type of contact when adding a new contact. Confusing? I hope not!

Now i'd like to use SPLookupAddNew for adding a new contact from the connection list. The thing is, it points to the default content type of the Contacts list when clicking "add new item".

My question is: What would be the best way accomplish to be able to choose a type of contact (Content type) when adding a new item in the "Contacts" list.


Oct 21, 2011 at 1:03 PM
SPLookupAddNew has really taken on a life of its own. I originally built it just to use myself as I was testing SPCascadeDropdowns as an easy way to add related items. Now everyone wants it to do much more, but it's tricky.

Keep in mind that the current form is *not* saved when you click on the SPLookipAddNew link, nor is the newly added value then selected. Both of these things are a part of the trickiness.

All that said, right now your users will have to select the Content Type manually.

Oct 21, 2011 at 2:07 PM

Thanks for the answer, i understand it's only about chaining using source without saving anything. My form doesn't need to be saved first since the add new option is the first option..

As an alternative then, is is possible to manually provide a contenttype id in the add new link instead of the default it's taking form the lookuplist?

Oct 22, 2011 at 2:42 PM

At the moment, SPLookupAddNew doesn't allow you to set a Content Type for the new item. I think that would make a nice little enhancement, so I'll add it to my list in the Issue Tracker. By passing the ContentTypeID into the NewForm for the list, we'll b e able to cxhoose the correct Content Type.

Usually, People have dedicated lists for the lookup columns with only one Content Type, so that hasn't ever come up before.


Oct 22, 2011 at 2:44 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Oct 22, 2011 at 2:47 PM

Actually, now that I'm reading through your post again, you want the Content Type to be variable based on the user's selection. That's a very unique requirement.

You could make that happen by altering the Add New link after the user makes their selection, passing that variably chosen ContentTypeID on the Query String in the href. I don't think anyone else is likely to want that functionality, so I don't think I'll add it to SPServices, though I will add the single ContentTypeID option.


Oct 24, 2011 at 9:00 AM

You are definately right about the uniqueness! But by just being able to specify a Content Type id you would give a good enough option to work something out which will work in my case. I'm sure it will be used by others as well.

Thanks for the answers and i'll be following!