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

Calendar with multiple (custom) content types

Dec 12, 2014 at 10:31 PM
Let's say I have a Calendar that can hold two custom content types:

Meeting (child of Event with two custom columns, Cliente and Ufficio):
  • Cliente is a lookup on Customers and I'm using it to construct the Title field of the Meeting
  • Ufficio is simply a multiple choice between three office locations
Court attendance (child of Event with three custom columns, Cliente, Sede, Tipo udienza):
  • Cliente is the same lookup as above
  • Sede is a lookup to a list of Court addresses (should go into Location)
  • Tipo udienza is a lookup to another list of attendance types (should be added to Description)
Should I perforce use two different Calendars, one for Meeting and the other to Court Attendance, or is there a way to discriminate (from inside the Javascript web part) the code that should be run for a Meeting and for a Court attendance?

Thanks in advance,
Best regards from Italy
Dec 15, 2014 at 4:19 AM
Edited Dec 15, 2014 at 4:28 AM
You can use the same Calendar if you'd like and use some code to detect when some of the fields don't exist.

In this case, an exception will be thrown when you try to get a field (Ufficio) which doesn't exist on the Court Attendance form:
// get field used on both forms
var cliente = SPUtility.GetSPField('Cliente');
try {
   var ufficio = SPUtility.GetSPField('Ufficio');
   // meeting form
   // do more stuff specific to meeting form
} catch (e) {
   // court attendance form
   var sede = SPUtility.GetSPField('Sede');
   var tipoUdienza = SPUtility.GetSPField('Tipo udienza');
   // do more stuff for court attendance form
}
Dec 15, 2014 at 6:10 AM
Edited Dec 15, 2014 at 6:27 AM
Thanks a lot! I'll proceed this way.
Can I use the same technique, paired with document.write('you are here') to debug what's going on into my webpart?
I used to be a developer-of-sort some ten years ago, but now my coding abilities seems to be all rusty and creaking...
Dec 16, 2014 at 2:53 PM
Edited Dec 16, 2014 at 3:14 PM
Hmmm... it seems that the Calendar has different behavior from the mere List.
Actually I've created two custom content types, one for Udienza (court attendance), another for Appuntamento (meeting).
I've associated these content types to specific Calendars, named respectively Udienze and Appuntamenti, while disallowing creation of simple Events on these calendars.
I've customized (Calendar/Customize list/Web parts/Default new... Default edit) adding my Content Editor web parts as previously (successfully) done for Contacts.

This is my code for Udienze, it seems however that it never gets executed (inserted try/catch to trap the errors but nothing shows up).

EDIT my code for Appuntamenti works perfectly, so it should be something wrong with Udienze's code (that has been somewhat copied from the first one).

I should figure it out by myself, sorry for bothering you.
Dec 17, 2014 at 12:26 PM
If you are using a modern browser (firefox, chrome, IE10+) then you can use console.log("hello!"); to print debug messages to the console.

It should work the same on the calendar list forms so I'm glad to hear it is working on your Appuntamenti form. When you don't get an exception, it could mean it is a problem loading jQuery or SPUtility. The developer tools which come with your browser are also useful for debugging this.
Marked as answer by rimmon1971 on 12/17/2014 at 7:49 AM
Dec 17, 2014 at 3:49 PM
I confirm that Udienze new/edit forms are now working correctly, after complete rewrite (I suspect having forgotten a "var" statement somewhere on the first release).
Dec 17, 2014 at 4:29 PM
Yikes, sorry to hear you had to rewrite it but I'm glad you got it working! :)
Dec 17, 2014 at 5:12 PM
I had only to copy Appuntamento's code and carefully editing it 😊
So... No big effort