How to get Versioned Multi Line Text as Plain Text of Multiline Text (Append Text/Version Applies) Field in SharePoint
Welcome Reader,
I have moved to a new blog site, so you can get same content from below new site URL!!
http://dishasharepointworld.blogspot.com/2009/06/how-to-get-versioned-multi-line-text-as_17.html
Please feel free to post your comments/feedback into new blog, I’ll be more than happy to assistant you.
Sorry for any inconvenience!!
Disha Shah
Hi,
Hope you are doing good. I just saw a whitepaper (http://www.combined-knowledge.com/Downloads/Modify_Alert_Notifications.pdf) on customizing the AlertTemplate.xml file . Need one help from you regarding that only. I am working on the Alert stuff. To be more clear: I created a workflow in sharepoint designer and it shoots the “ a task has been assigned to you by system account” email to all the people. What I want is I need to put my own text and some lookup values like the link to the current Infopath form and some more relevant text related to that. So how can I do that?
Would appreciate if you can give quick reply.
Looking forward to hear from you.
Regards
Sumeet Gandhi
Hey,
Please refer below link which will give you detail description regarding how to send custom email notification when any task is assigned to user; refer specific section “Send your own custom task notifications”.
http://office.microsoft.com/en-us/sharepointdesigner/HA102390421033.aspx
Maybe this will also helpful for you : http://spdactivities.codeplex.com/
Thanks,
Disha
This code doesn’t work. The text that is returned by field.GetFieldValueAsText() for each version actually contains all the previous version’s comments as well, appended together.
BTW also, is it possible to modify each version’s comment to include text saying stuff like ‘Status changed to “Completed”‘ (prepended on the existing comment?’
I’m assuming the multiline text field in question is the ‘Comments’ field of course.
Many thanks!!
My apologies, I was using the SharepointBoost discussion column, which apparently has this incorrect behavior. The standard Sharepoint control does not.
Hey Chris,
It’s good to see that you have raised a question by yourself and gave the answer
That’s very good that you got your solution, enjoy!!
-Disha Shah
Disha – Thanks for the post. It seems to head me in the direction I’d like to go, but I have no idea where to start. If you’re so inclined, I’d very much appreciate any assistance you can provide.
I have a default Sharepoint issues list I am trying to use as a test. I’ve entered an issue and created 2 comments (“Comment #1″ and “Comment #2″). They are shown in SP as version 1.0 and 2.0 respectively. I would like to get the full comment history combined into one text box of an Infopath form field, as Infopath is where we have the managers perform their ticket entries and hopefully updates. The bulk of the fields downloads fine via sharepoint data connection into a repeating table. I only get the most recent comment for the V3Comment field. How should I go about retrieving the comment history and summarize it into a text field? At the moment the form has no underlying code.
Thanks for any suggestions, guidance, assistance!
Hi Disha, i am suman. I wish you are the right person to help me and my job..!
This is my 1st project as a sharepoint developer and not much experience as they think.. so please help me to solve this issue…!
they assigned me one urgent task to “create custom field(multiline text). this filed should accept only if the user enters grater than 16 characters and it should give validation error if the user enters less than 16 characters..and the imp thing is we should enable versioning and append existing text on this custom field( we need to see the history of the previous entries on this field)..
This is my task…I achieved this task by adding javascript code to editform.aspx(we already have OOB multiline field) This is my script(
function PreSaveAction()
{
var input = getTagFromIdentifierAndTitle(“textarea”,””,”Suman”);
if(input.value.length <16)
{
alert("enter atleast 16 characters ");
return false; // Cancel the item save process
}
return true;
}
function getTagFromIdentifierAndTitle(tagName, identifier, title)
{
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++)
{
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length – len))
{
return tags[i];
}
}
return null;
}
)
But,THEY DONT WANT THIS METHOD.. THEY WANT ONLY CUSTOM FIELD…THEY DONT WANT TO EDIT THE OOB EDITFORM.ASPX..
PLEASE, GIVE ME THE LOGIC FOR MY TASK,I WILL BUILD THE SOLUTION(I JUST NEED LOGIC)..PLEASE HELP ME…!
PLEASE LET ME KNOW IF YOU NEED ANY EXTRA INFORMATION…!!
DISHA..PLEASE HELP ME AND SAVE MY JOB …!!!
THANKS,
SUMAN
SPULUSU@MAIL.COM
Suman
Very Simple answer, go with the event handler named as “Item Adding” and in that eventhandler check whether that textbox has 16 charachters or not in “ItemAdding” event!!!If not add a message “Please enter more than 16 characters”
Follow this blog link ,
http://dishashah.wordpress.com/2009/06/10/sharepoint-list-event-handler-types-and-example/
http://dishashah.wordpress.com/2009/06/23/synchronous-event-hanlders-in-sharepoint-with-itemadding-and-itemupdating/
Feel free to comment if you have any question!!!
Hope this helps!!!
Disha Shah
Hi Disha,
Thanks for your response…!
How can i achieve my 2nd part of the requirement…I need it as version enabled(append existing text) field…!!
Suman
Hi Suman
Well you just need to take a field which has a type Multi Line Text with Version and selected ”Allow append text” as option and you just need to add “Item Adding” event handler to check whether they have entered 16 characters or not!!!!
See both are different things , sharepoint does its work with the type which has Multi Line Text with Version and selected ”Allow append text” as option and you have to write event hanlder for 16 charachters minimum validation!!!
Do you face any problem if you have “Multi Line” Text with Version and selected ”Allow append text” as option and itemadding eventhandler?
Please follow this link where there is a logic for getting version multipline text!!!
http://dishashah.wordpress.com/2009/06/18/how-to-get-versioned-multiline-text-as-plain-text-of-multilinetextappend-textversion-applies-field-in-sharepoint/
now add this logic in the Itemadding Eventhandler , check latest version of that text box and validate whether it has 16 characters or not .
Hope this helps!!!
Still any question Leave comment!!!
Thanks & Regards
Disha Shah
I think i am missing something…!!
My Requirement is to create a custom field, which needs to have both these(minimun char length 16 and versioning Allow append text).
If we write the custom field for min char length then need to write code for versioning(allow append text also right? (or if we create custom field with type multiline, it(SharePoint) will automatically give this option while adding this column to select the “Allow append text”(As like OOB Multiline text field)… !!
Thank you so much for replies…!!
Suman
Suman
Let us talk about your original requirement.Client needs that they should have one mutitext field control where versioning and history should be available as well as when they enter some information on multiple text field they should enter atleast 16 characters!!!!
Forget about sharepoint and everything , just requirement!!!Is it correst what I am understanding?
Waiting for reply!!!
Thanks and Regards
Disha Shah
EXACTLY….!!!!!
Thats what my requiremnt is…!!
thanks a ton..!!
Suman
Great!!!!So now let us think about that we need to achive that requirement by sharepoint!!!
We have 2 requirements needs to accomplish,
1> It must be multipleText Field with Versioning and History enabled and
2> Whenever user enters some text it must be 16 characters not less than that.
So now
1> It must be multipleText Field with Versioning and History enabled and (it is accomplished by Create column which has Multiple Line text with versioning and history is enabled.
2> Whenever user enters some text it must be 16 characters not less than that.(it is accomplished by “ItemAdding” event handler , then you need to attach that eventhandler with that list)
No need to develop Custom Field….
If you have any question please let me know..
Thanks & Regards
Disha Shah
Wow..Okey..!! Now i got your solution…!
You want me to write event handler and deply that event handler to that perticular list and use the OOB multiline text field…AM i right(hopefully..)?
To be frank never wrote event handler(but have some idea how it works..)
If you can give me the steps to write code and deploy on to my test server..that could be huge help…(i kow its its little heavy help i am asking . but i wont ask you again this huge help..)
Hope you will help me..!( i will be happy if you send me the solution file)
Suman
Disha,
I was reaidng this post http://farhanfaiz.wordpress.com/2007/12/31/creating-adding-an-event-handler/
It might help me while writing event handler..If you can(please) send me the code for my requiremnt i will follow this post for event handler..!
Please let me know …!!
Thanks again..!
Suman
Suman
Exactly!!!Whatver you understand is right!!!!!!!
Whatver you are reading for eventhandler is also right !!!!
Please follow this link,Everything is explained very well
http://msdn.microsoft.com/en-us/library/ms453149.aspx
http://blogs.msdn.com/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx
I am ready to assistant for any huge help not today but anytime and I promise I will do my best for that but I wish you first atleast make attempt by following above link.
Well, Logic you should develop,If you stuck anywhere let me know I m here only, just leave a comment.
Hint: Write “Itemadding” Event handler, to get items follow this links
http://dishashah.wordpress.com/2009/06/23/synchronous-event-hanlders-in-sharepoint-with-itemadding-and-itemupdating/
Thanks and Regards
Disha Shah
Thank you so much…I will start and try to create an event handler…!
Will see what i can make…!!
Suman
Disha,
Logic i am not able to get it..!Here is where i struck for logic..
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace AssistanceNotesEventHandler
{
public class AssistanceNotesEventHandler: SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
string strName = string.Empty;
foreach (AssistanceNotesEventHandler entry in properties.AfterProperties)
}
}
}
what sould i do..?
Suman
It should like this
In your code this one is wrong part,
foreach (AssistanceNotesEventHandler entry in properties.AfterProperties)
it should like
foreach (DictionaryEntry entry in properties.AfterProperties)
{
if (entry.Key.Equals(Fieldname)) \\where 16 characters is limit minimum
{
strName = entry.Value.ToString();
break;
}
}
if(strName.Trim().Lengh <16 )
{
properties.Cancel = true;
properties.ErrorMessage =”Invalid value!!!It must contain atleast 16 charactets”; \\Custom validation message
}
One more thing Please read what are types of eventhandler and what is difference and why we use Directory entry?(basic points)
http://dishashah.wordpress.com/2009/06/10/sharepoint-list-event-handler-types-and-example/
http://dishashah.wordpress.com/2009/06/23/synchronous-event-hanlders-in-sharepoint-with-itemadding-and-itemupdating/
Thanks & Regards
Disha Shah
Disha,
As you instructed, i am done with writing eventhandler. Here is my code for assistacenoteseventhandler.cs
public class AssistanceNotesEventHandler: SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
string strName = string.Empty;
foreach (DictionaryEntry entry in properties.AfterProperties)
{
if(entry.Key.Equals(AssistanceNotes))
{
strName = entry.Value.Tostring();
break;
}
}
if(strName.Trim().Length <16 )
{
properties.Cancel = true;
properties.ErrorMessage = "Invalid Value. You much enter atleast 16 characters";
}
}
}
Next step is to deploy to my site.(if i am not wrong.). Now Should i follow from step 1.6 (http://farhanfaiz.wordpress.com/2007/12/31/creating-adding-an-event-handler) ..!!
in that post they deployed as a feature, but is there any otehr way to deploy this event handler bcause, feature requires IIS reset, if client didnt want to reset IIS on Production environment)..!!
Thanks,
Suman
Disha,
When i build my project i m getting two errors 1)”DicrionaryEntry” Could not be found 2″assistanceNotes” doesnot exist in the current context.
Any assembly i ned to add otehr than microsoft.sharepoint.dll ?
Suman
Suman
I think you are new to .NET Developer too.
You need to add this assembly System.Collections.DictionaryEntry assembly for “DictionaryEntry” and also as I instructed I told you write down the field name
if(entry.Key.Equals(AssistanceNotes)) //Wrong
If “AssistanceNotes” is your fieldname you should write in double quotes.
if(entry.Key.Equals(“AssistanceNotes”)) //I had considered your field name as “AssistanceNotes”.Rightone
Feature does not need IISReset.So deploy with the feature.
Hope this helps!!!!!
Thanks & Regards
Disha Shah
Yes, i am very much new to .Net
Thank you..!
Suman
ok..!
Disha,
Once i am done with event handler, I signed the assebly and Copied DLL to GAC.
Created a console app to register this event handler . Here is the code namespace RegApp
When i run this app, blank console window is opening.. Nothing was happened on the listfield as we expected..!!
Is there anything i am missing .!!
Suman
Console.ReadKey();
SPSite collection = new SPSite(“SiteCollectionURL”);
//SPUser user = new SPUser();
SPWeb site = collection.RootWeb;
SPList list = site.Lists["Making Pune Successful"];
string asmName = “AssistanceNotesEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7afe2bf3d34ca4fb”;
string className = “AssistanceNotesEventHandler.AssistanceNotesEventHandlerClass”;
list.EventReceivers.Add(SPEventReceiverType.ItemAdding, asmName, className);
site.Dispose();
collection.Dispose();
Console.WriteLine(“Successfully Registered”);
Environment.Exit(0);
Suman
Whatver you did is right, but still can you please follow this link it shows messages if it is successfully registered.
http://blog.sharepointdevelopment.nl/post/Using-a-console-application-to-install-an-eventhandler.aspx
One more thing I want to make sure is did you specify right column name in eventhandler of itemadding?It means in this line
if(entry.Key.Equals(“AssistanceNotes”)) where “AssistanceNotes” is your column name?
Thanks & Regards
Disha Shah
Disha, Here is my code for Console application to register the eventhandler.. i am getting 1 error at “”"” myList.EventReceivers.Add(SPEventReceiverType.ItemAdding, assemblyName, className);”"”" error: use of unassigned local variable ‘myList.
Code: try
{
Console.ReadKey();
SPSite sitecollection = new SPSite(“http://SiteCollectionName”);
SPWeb site = sitecollection.AllWebs[0];
SPList myList;
foreach (SPList l in site.Lists)
{
Console.WriteLine(l.Title);
if (l.Title == “Making Pune Successful”)
{
myList = l;
}
}
string assemblyName = “AssistanceNotesEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7afe2bf3d34ca4fb”;
string className = “AssistanceNotesEventHandler.SPItemEventReceiver”;
myList.EventReceivers.Add(SPEventReceiverType.ItemAdding, assemblyName, className);
SPEventReceiverDefinitionCollection registeredEvents = myList.EventReceivers;
foreach (SPEventReceiverDefinition def1 in registeredEvents)
{
Console.WriteLine(“Succesfully added eventhandler:” +
def1.Type.ToString());
}
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
Disha,
Finally i am able to deploy the event handler(this time i deployed as a feature)..
BUT nothing is working as we expected… Not showing error message..
Actually, in our eventhandler code, we didnt give list name( we justgave column name right.. how can it apply to that perticular list..?)
My code for event handler : public class AssistanceNotesEventHandler: SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
string strName = string.Empty;
foreach (DictionaryEntry entry in properties.AfterProperties)
{
if(entry.Key.Equals(“Comments”))
{
strName = entry.Value.ToString();
break;
}
}
if(strName.Trim().Length <16 )
{
properties.Cancel = true;
properties.ErrorMessage = "Invalid Value. You must enter atleast 16 characters";
}
}
}
feature.xml :
Elements.xml ::
AssistanceNotesEventHandler
ItemAdding
10000
AssistanceNotesEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7afe2bf3d34ca4fb
AssistanceNotesEventHandler.SPItemEventReceiver
My existing multiline text column is “Comments”..List Name is ” Making pune successful”…!!
Please give me the mistakes..( hope i wont disturb you again on this task..)…!!
Thanks,
Suman
Suman
When you Register Event Handler at that time you already specified listtemplate in your elements.xml.So it fires for that list.So Verify the listtemplate please.
If possible please debug the eventhandler with w3wp.exe so you have better idea for both whether itemeventhandler is fired or not and if yes firing what is error it is throwing?
Now error can be one reason that Comments is multiline text so may be it is “StringBuilder” Type rather than String.
Thanks & Regards
Disha Shah
Hi Disha..!
I understood how it fires for the list,i gave the list templateID in elements.xml(104)..!
i tried all possible ways to debug and find the error cause.. but couldn’t find it..!!As this is my 1st task in this company every one are on my head..i dont have much time to resolve it so went back to old solution which is creating a custom filed..!
Created a custom field with required validator(atleast 16 charactors)..! it works well but didnt solve my requirement completely..! Copied DLL to GAC and added FLDTYPES_***.xml in [12]XML..! i can use this custom field but still need some more..
1)If i enter <16 characters, its giving error message properly but if i dont enter anything(blank in this field) nd hit OK, its not giving any error message(it should give 'must enter 16 chars)..!
2) If i enter 16)
{
}
else
{
throw new Microsoft.SharePoint.SPFieldValidationException(“You must enter atleast 16 characters” + myVal);
}
return myVal;
}
public override object GetFieldValue(string value)
{
if (String.IsNullOrEmpty(value))
return null;
this.fldvalue = value;
return value;
}}}
FLDTYPES_AssistanceNotes.xml :: Assistance Notes1
Note
Assistance Notes1
Assistance Notes1
TRUE
TRUE
TRUE
TRUE
ntext
TRUE
RIAssistanceNotes.RISPFieldAssistanceNotes,AssistanceNotes,Version=1.0.0.0,Culture=neutral,PublicKeyToken=eccf9d7dcc95c57f
thanks a ton…!!
Suman
Hi Disha..!
I understood how it fires for the list,i gave the list templateID in elements.xml(104)..!
i tried all possible ways to debug and find the error cause.. but couldn’t find it..!!As this is my 1st task in this company every one are on my head..i dont have much time to resolve it so went back to old solution which is creating a custom filed..!
Created a custom field with required validator(atleast 16 charactors)..! it works well but didnt solve my requirement completely..! Copied DLL to GAC and added FLDTYPES_***.xml in [12]XML..! i can use this custom field but still need some more..
1)If i enter <16 characters, its giving error message properly but if i dont enter anything(blank in this field) nd hit OK, its not giving any error message(it should give 'must enter 16 chars)..!
2) If i enter <16 chars, errormessage is showing including with entered text(Ex: if i enter "thisisTest",error messate is showing as "you must enter 16charsthisisTest
3))As you know, i need to enable versioning on this field with append existing text. (this column should look like this in edit and view pages http://www.filetransit.com/images/screen/6b838ba3662ed82965effa76e8a7cdeb_SharePoint_Discussion_Column.jpg
I am taking day off tomorrow as i cant face them tomorrow in the office.. Will try to work on these atleast to save my job..!
Here is the code for this project, please suggest me if you can(please dont get irritated ..)
namespace RIAssistanceNotes
{
class RISPFieldAssistanceNotes : SPFieldMultiLineText
{
#region Contstructors
public string fldvalue = string.Empty;
public RISPFieldAssistanceNotes(SPFieldCollection fields, string fieldName): base(fields, fieldName)
{
}
public RISPFieldAssistanceNotes(Microsoft.SharePoint.SPFieldCollection fields, string typeName, string displayName)
: base(fields, typeName, displayName)
{
}
#endregion
public override string GetValidatedString(object value)
{
string myVal = value as string;
if (myVal == null)
return String.Empty;
int strlen = myVal.Length;
if (strlen > 16)
{
}
else
{
throw new Microsoft.SharePoint.SPFieldValidationException(“You must enter atleast 16 characters” + myVal);
}
return myVal;
}
public override object GetFieldValue(string value)
{
if (String.IsNullOrEmpty(value))
return null;
this.fldvalue = value;
return value;
}}}
thanks a ton…!!
Suman
I am able to resolve my 2nd issue(above mentioned)…!!
Thanks..!
Hi Suman
It is good to know that you completed your assignment successfully!!!!!!
Thanks & Regards
Disha Shah
No i haven’t, part of it completed…Please 23 and 24th comment here…!
Suman
disha,
please read 23rd and 24th comments here and reply me..
waiting for your reply…!!
Suman
Suman
Suggestions !!!!
1> You should Override this method too
public override string GetValidatedString(object value)
{
if (field == null)
{
throw new ArgumentException(“Invalid value.”);
}
else
{
//Logic
}
}
2> If i enter 16)
{
}
else
{
throw new Microsoft.SharePoint.SPFieldValidationException(“You must enter atleast 16 characters” + myVal);
}
return myVal;
}
here you shd change with
If i enter 16)
{
}
else
{
throw new Microsoft.SharePoint.SPFieldValidationException(“You must enter atleast 16 characters” ); //you write myval that is wrong
}
return myVal;
}
3> Please tell me which base type you have taken for customfield like SPFieldMultiColumn which one?
Hope this helps
Thanks and Regards
Disha Shah
Thanks Disha.. eagerly waiting for yout reply..!!
I am able to took care of 1st 2 issues..!
I am worried about 3rd issue..!
i used “SPFieldMultiLineText” …!
Thanks a ton..!
Suman
Hi Disha,
If you get a chance, can you give me solution …!!!