Sharepoint - change way of displaying a field on a list - sharepoint

I have a sharepoint list that contains a multiple lookup field. I would like to change the way its values are displayed (normaly you get links to chosen items like item1;item2;item3), so that I could for instance construct my own link to redirect me to the source list filtered by items chosen on this lookup.
I try to do that by creating a custom field by that is inheriting SPFieldLookup, but i'm a bit stuck since I can't don't know which method/property to override to change what is being displayed (if this is possible at all). Any help would be appreciated

I'd create a custom field type that inherits from SPFieldLookup. But instead of do the rendering server side I'd use a XSTL to render the field:
How to: Customize the Rendering of a Field on a List View
This way you do not have to implement a custom SPField class at all. You just have to create a custom field type definition that points to the OOTB SPLookupField.
<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">CustomLookupField</Field>
<Field Name="TypeDisplayName">Custom Lookup Field</Field>
<Field Name="TypeShortDescription">Custom Lookup Field</Field>
<Field Name="FieldTypeClass">Microsoft.SharePoint.SPFieldLookup</Field>
<Field Name="ParentType">Lookup</Field>
</FieldType>
</FieldTypes>

Related

SharePoint update list item through web service using DisplayName

To add a list item in SharePoint 2007/2010 I currently use the following XML:
<Batch OnError='Continue' ListVersion="1">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="Title">anyTitle</Field>
<Field Name="Account_x0020_Name">SomeText</Field>
</Method>
</Batch>
Sometimes the internal name is not equal to the display name. For example here the DisplayName is "Account Name" but its internal name is "Account_x0020_Name".
Is there any way to create a new list item using the DisplayName instead of the internal name?
I've already tried using <Field DisplayName="Account Name">SomeText</Field> but that gives a SoapException.
Any Ideas?
You need to use the Internal Field Name. The easiest way to get it is via list/library settings, selecting the field and looking for the name in the URL.

Sharepoint 2007: Create a multi-line text custom property for a custom field type?

I'm trying to extend the built-in Choice field type to include another piece of data: a correct answer. With this, users would be able to create their own tests directly within Sharepoint instead of having to use InfoPath or some other convoluted solution. I was hoping to just inherit the existing SPFieldChoice type and add one more custom property to hold an integer representing the correct answer from the choices entered.
I've got a FieldTestQuestion class that inherits from SPFieldChoice along with a pretty basic TestQuestionFieldControl class inheriting from RadioButtonChoiceField. My fldtypes_TestQuestionField.xml file:
<FieldTypes>
<FieldType>
<Field Name="TypeName">TestQuestion</Field>
<Field Name="ParentType">Choice</Field>
<Field Name="TypeDisplayName">Test Question (Multiple choice)</Field>
<Field Name="TypeShortDescription">Test Question (Multiple choice)</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowInColumnTemplateCreate">TRUE</Field>
<Field Name="FieldTypeClass">MyCustomFieldTypes.FieldTestQuestion,MyCustomFieldTypes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=****</Field>
<PropertySchema>
<Fields>
<Field Name="CorrectAnswer" DisplayName="Correct answer (line number)" Type="Integer">
<Default></Default>
</Field>
</Fields>
</PropertySchema>
</FieldType>
</FieldTypes>
Unfortunately, this is what renders when I try adding a column of this type:
(source: mudman.us)
No option to add the choices as with the Choice field type:
(source: mudman.us)
What do I need to put in my fldTypes_.xml to tell Sharepoint to either (a) use the existing custom properties for the Choice column and ADD the extra property I specified or (b) specifically define a multi-line text custom property?
It would appear the Choice input box is being created specifically for SPFieldChoice columns; one of many un-inheritable features. This means that you're unlikely to be able to persuade SharePoint to reproduce it for your custom field type.
My advice would be to go for option b), and create it yourself. I believe adding this to the <fields> element will do the trick:
<Field Name="ChoiceFix" DisplayName="Type each choice on a separate line:" Type="Note" />
Be warned that I haven't tested this solution reliability, and you may have to go down the spiky and unpleasant route of making your own Field Editor Control.

Programatically updating SharePoint custom field type column value [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I have created a custom field type (say 'Sample') in SharePoint which is based on 'multiline text' field type. Now I have created a new column(say 'test') of type 'Sample' in a list. I created some list items.
I can edit the column value successfully from SharePoint UI (through edit form). But when I try to modify the value of 'test' column programatically for any list item, value of 'test' column for that list item becomes null/empty.
Any idea why this probem is occuring?? Below is the filedtypes xml that I am using
<?xml version="1.0" encoding="utf-8"?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">Sample</Field>
<Field Name="ParentType">Note</Field>
<Field Name="TypeDisplayName">Sample</Field>
<Field Name="TypeShortDescription">Sample</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowInListCreate">TRUE</Field>
<Field Name="ShowInSurveyCreate">TRUE</Field>
<Field Name="ShowInDocumentLibraryCreate">TRUE</Field>
<Field Name="ShowInColumnTemplateCreate">TRUE</Field>
<Field Name="FieldTypeClass">
SharePoint.Sample.FieldType, SharePoint.Sample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c5560aa45b5518dc
</Field>
<Field Name="FieldEditorUserControl">
/_controltemplates/FieldEditor.ascx
</Field>
<PropertySchema>
<Fields>
<Field Name="DisplayedListBoxProperty" DisplayName="DisplayedListBoxProperty"
Type="Text" Hidden="True">
<Default>"abc"</Default>
</Field>
</Fields>
</PropertySchema>
</FieldType>
</FieldTypes>
Code that I am using to edit:
SPSite site = new SPSite("site url")
SPWeb web = site.OpenWeb();
SPList list = web.Lists["MyList"];
SPListItem item = list.Items[0];
item["test"] = "xyz"; //becomes null after update
item["numCol"] = "34"; //Gets updated to new value 34 after update
web.AllowUnsafeUpdates = true;
item.Update();
One Important thing: This code runs in itemupdating eventhadler of another list.
With your code, there is problem with your Custom Field Type with "FieldTypeClass". Try this 'SharePoint.Sample.FieldType, SharePoint.Sample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c5560aa45b5518dc'
hope this will helps you.
Well I found the problem area. There is a function called GetValidatedString() which is used for any validation on the value. This function gets called even in case when you update value programmatically.
It was creating a problem.

Adding a Column to a Generic List INstance during feature provisioning

I'm trying to create a solution package for a set of features within a SharePoint site. I want to create an instance of a generic list (using ListInstance in the element manifest) and add an additional column to it (since by default they only have a Title column) without having to go through activation code.
Is there a way to do this through CAML? So, far I'm sort of stuck with the idea of having to create a custom content type but that means I would have to have a separate feature that activates at the Site level to deploy the content type first.
I believe this is what you are looking for, snippets:<!--Add a field reference for the custom field.-->
<FieldRef
ID="{AD22016D-BC8B-4631-A0A3-5E84C6CFA7EC}"
Name="FavoriteColor"
Required="TRUE"
ShowInNewForm="TRUE"
ShowInEditForm="TRUE"/>
and then:
<Fields>
<Field
Type="Choice"
Name="FavoriteColor"
DisplayName="Favorite Color">
<CHOICES>
<CHOICE>Red</CHOICE>
<CHOICE>Green</CHOICE>
<CHOICE>Blue</CHOICE>
</CHOICES>
</Field>
</Fields>
Making sure it is added to the view<ViewFields>
<FieldRef Name="FavoriteColor"/>
</ViewFields>

CAML cannot reference Custom Properties in custom fields

I am trying to create a custom field type in SharePoint.
My custom field type has a custom property called CustomProperty.
<FieldTypes>
<FieldType>
<Field Name="TypeName">CustomField</Field>
<Field Name="InternalType">CustomField</Field>
..............................
..............................
<PropertySchema>
<Fields>
<Field Name="CustomProperty" DisplayName="CustomProperty" Type="Text" Hidden="TRUE" />
</Fields>
<RenderPattern Name="DisplayPattern">
<Property Select="CustomProperty" />
</RenderPattern>
</FieldType>
</FieldTypes>
I am trying to render the value of this custom property in the DisplayPattern.
But it looks like the CAML is not able to reference the custom properties.
I am not getting any value for the CustomValue property even though it is set correctly.
Any idea how to refer custom properties in CAML?
Unfortunately there is no straightforward way of achieving this, from what I've seen.
Your best option is to look at using this.GetCustomProperty("CustomProperty") within the overrided GetFieldValue function (or GetFieldValueAsHtml for a Note field).
The value string passed into the GetFieldValue function is the output from your CAML, so you can append to it and pass it on out.
Here is a sample:
http://blogs.msdn.com/toddca/archive/2009/01/23/customizing-the-rendering-of-a-custom-spfield.aspx
I haven’t tried it myself, and I have no idea if changing the SchemaXml could cause any unexpected problems.

Resources