Can I create my own formula for calculated field in Sharepoint 2010 using C# - sharepoint

I want to create a programmatically calculated field for Sharepoint 2010 using Visual Studio 2010 in C# language.
Is there a way to set a formula that will call to my own function and return a result back to the field?
My scenario:
let's say I want to create a field that always returned the sum between two other fields,
but I don't want to use something like "=sum([filed1],[field2])".
I want to call to function "calc2Fields()" and return a result.
Is it possible?

No, it is not possible. By changing the formula you are not adding any internal logic, so the field will not know what to do with your function. You can however build a custom field and incorporate there any logic you need. Of course it is not going to be identical to the built-in calculate field, but then you can add your own functions.

You will have to create your own custom field with this logic in.
Customizing the User Experience of SharePoint: Custom fields deep dive

Related

Unique Title value in SharePoint 2013

I defined a custom list, and there was a column named Title, the SharePoint standard column. I wanted to make Title value be unique. I have set Indexed and EnforceUniqueValues as TRUE, but it doesn't work. What settings should I do in the scheme.xml with no coding works? I'm using Sandbox Solution.
By the way, I can set unique value on other columns I defined by these settings in scheme.xml.
I guess I need to modify the definition of the content type, but Title column is in List Content Type, I cannot modify it. Or do you know how to get the scheme.xml that modified by settings in web?
but you can achieve that using visual studio and creating an template list and list instance , avoiding the direct schemme modification. More simple and fast. I've created list and unique reatrictions using that approach.

Validating special column types in SharePoint 2010

How do I validate special column types, e.g. phone, e-mail etc in SharePoint 2010?
I guess I could use an ASP.NET RegularExpressionValidator but surely there must be a simpler way?
There isn't really an easier way. If you want to compare values of one column to another or if you want very basic validation you can use Column Validation, but it doesn't support regular expressions so it won't help with things like email.
You could use jQuery to do the validation, which is a bit easier than using a validator, although it only checks on the client side.
Another option if you have the Enterprise version of SharePoint is to use InfoPath to edit the list. With InfoPath you can easily add regex validation.

SharePoint (2010): Field for (multi) currency...?

old problem now getting new. Anyone has a good idea for storing currency values in a sharepoint list? Problem is - there is a currency field, but it is not multi-currency enabled.
I could obviously store the value in two fields (currency lookup from a list, value in second field), but I take it as wondering whether there is a more viable approach that.
You could create your own custom field type
Custom Field Type
Building Custom Field Types in Windows SharePoint Services 3.0

Sharepoint custom list, dynamic field?

Hey guys, just wondering if their is a simple way to create an Item in a custom list but i need that item to be dynamic. The user can click add more to get another field that would hold the same type of data an unlimited amount of time.
If i could even just add an excel spreadsheet type of field that would work also. But excel wouldnt need to be a requirement on the users machine.
I thought i had read somewhere you could do this using info path but i cant seem to find anything relating to it on google.
The InfoPath feature is called a "repeating section". There is information on how to set that up in Office Online.
If you wanted to achieve this entirely in SharePoint, the problem is that there can only be a fixed number of fields in a list. So you could create as many that would ever be used and just display all of those. Or to make it much nicer for the user incorporate jQuery to hide all of the fields except the first one and provide a button for them to click that unhides the next one.
There is good information on how to access list form fields using jQuery in the question How can I set the default value in a SharePoint list field, based on the value in another field?

Auto number column in SharePoint list

In a SharePoint list I want an auto number column that as I add to the list gets incremented. How best can I go about this?
Sharepoint Lists automatically have an column with "ID" which auto increments. You simply need to select this column from the "modify view" screen to view it.
You can't add a new unique auto-generated ID to a SharePoint list, but there already is one there! If you edit the "All Items" view you will see a list of columns that do not have the display option checked.
There are quite a few of these columns that exist but that are never displayed, like "Created By" and "Created". These fields are used within SharePoint, but they are not displayed by default so as not to clutter up the display. You can't edit these fields, but you can display them to the user. if you check the "Display" box beside the ID field you will get a unique and auto-generated ID field displayed in your list.
Check out: Unique ID in SharePoint list
If you want to control the formatting of the unique identifier you can create your own <FieldType> in SharePoint. MSDN also has a visual How-To. This basically means that you're creating a custom column.
WSS defines the Counter field type (which is what the ID column above is using). I've never had the need to re-use this or extend it, but it should be possible.
A solution might exist without creating a custom <FieldType>. For example: if you wanted unique IDs like CUST1, CUST2, ... it might be possible to create a Calculated column and use the value of the ID column in you formula (="CUST" & [ID]). I haven't tried this, but this should work :)
I had this issue with a custom list and while it's not possible to use the auto-generated ID column to create a calculated column, it is possible to use a workflow to do the heavy lifting.
I created a new workflow variable of type Number and set it to be the value of the ID column in the current item. Then it's simply a matter of calculating the custom column value and setting it - in my case I just needed the numbering to begin at 100,000.
it's in there by default. It's the id field.
If you want something beyond the ID column that's there in all lists, you're probably going to have to resort to an Event Receiver on the list that "calculates" what the value of your unique identified should be or using a custom field type that has the required logic embedded in this. Unfortunately, both of these options will require writing and deploying custom code to the server and deploying assemblies to the GAC, which can be frowned upon in environments where you don't have complete control over the servers.
If you don't need the unique identifier to show up immediately, you could probably generate it via a workflow (either with SharePoint Designer or a custom WF workflow built in Visual Studio).
Unfortunately, calculated columns, which seem like an obvious solution, won't work for this purpose because the ID is not yet assigned when the calculation is attempted. If you go in after the fact and edit the item, the calculation may achieve what you want, but on initial creation of a new item it will not be calculated correctly.
As stated, all objects in sharepoint contain some sort of unique identifier (often an integer based counter for list items, and GUIDs for lists).
That said, there is also a feature available at http://www.codeplex.com/features called "Unique Column Policy", designed to add an other column with a unique value. A complete writeup is available at http://scothillier.spaces.live.com/blog/cns!8F5DEA8AEA9E6FBB!293.entry
So I am not sure I can really think of why you would actually need a "site collection unique" id, so maybe you can comment and let us know what is actually trying to be accomplished here...
Either way, all items have a UniqueID property that is a GUID if you really need it: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.uniqueid.aspx
Peetha has the best idea, I've done the same with a custom list in our SP site. Using a workflow to auto increment is the best way, and it is not that difficult. Check this website out: http://splittingshares.wordpress.com/2008/04/11/auto-increment-a-number-in-a-new-list-item/
I give much appreciation to the person who posted that solution, it is very cool!!

Resources