Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have tried to use an Event Receiver with ItemAdding event to set the Title field of a Document, so that when a end user uploads a document and is presented with the Edit Item page where they are forced to fill in required fields...I can populate the Title field or other fields.

I have used:

properties.AfterProperties["Title"] = "blah";
base.ItemAdding(properties);

This does not come up in the Title field in the form on the page. It is definately triggering the Event Receiver method as I've had it break on the break point.

I created my own field called "Container Record Number" with internal name "Container_x0020_Record_x0020_Number" interestingly this didn't work:

properties.AfterProperties["Container_x0020_Record_x0020_Number"] = "blah";
base.ItemAdding(properties);

but this did!

properties.AfterProperties["Container Record Number"] = "blah";
base.ItemAdding(properties);

So DisplayName seems to be the key here...and it looks like Title is doing something special in the base.ItemAdding(properties) for some reason.

Any suggestions?

ItemAdded will work by saving the "blah" into the Title but not until after the end user has clicked OK and saved the Edit Item page.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

enter link description hereI always do this with JavaScript (now always jQuery) based on values passed on the Query String. I know, not "real" development, but it works! What are you basing the Title value on?

Well, if you're going to call it a "hack"... ;-) This article was the basis for all of my thinking on this: http://blogs.msdn.com/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx

jQuery selectors make finding the objects on the page so much easier. Something like: $("input:[Title='Title']") is all you need to find the input field.

I have yet to convert this little bit to jQuery, but here's the Query String grabbing code:

var vals = new Object();
var qs = location.search.substring(1, location.search.length);
var args = qs.split("&");
for (var i=0; i < args.length; i++) {
  var nameVal = args[i].split("=");
  var temp = unescape(nameVal[1]).split('+');
  nameVal[1] = temp.join(' ');
  vals[nameVal[0]] = nameVal[1];
}

and yes, I copy EditForm.aspx and add the script into the copy, then set the copy as the supporting form for the list.

M.

EDIT 2011-08-04 I added a function to SPServices called SPGetQueryString called for this a long while back.

share|improve this answer
    
shudder jQuery...you're the second person to answer with that ;-) OK OK I'll use jQuery what approach would you take to do this? e.g. modify EditForm.aspx and add a JavaScript <script> block in there with the hacks? –  Anonymous Nov 11 '09 at 4:01
    
For some things jQuery is the only practical option, as 'hacky' as it sometimes feels. –  Alex Angas Nov 11 '09 at 9:33
    
It's still code, and if you do it right, I don't think it's "hacky"! There's more than one way to skin a cat (as my ninth grade algebra teacher Elmo McFadden used to say). –  Marc D Anderson Nov 11 '09 at 12:54

This is a common problem with the ItemAdding / ItemUpdating event receivers when uploading Office 2007 documents.

The XML document parser will not honour the Internal Name as an indexer into the AfterProperties collection. Instead, it appears to use the Title as an indexer in most cases. Even better than the title is the XmlConvert.Decode(InternalName) which seems to work consistently.

My understanding is that the xml parser disregards the after properties changes in view of the properties from the 2007 document being promoted to the SharePoint fields, unless the after properties are changed properties.

It gets more interesting in the ItemUpdating event receiver with more fields being cleared / reverting to document values but I don't have a clear understanding of the rules the document parser uses to evaluate property promotion. Ideally, I would love to have a setting that disables field promotion SPECIFICALLY for my custom field because I am setting the value in the after properties.

share|improve this answer

Try using BeforeProperties. Also the hashtable uses display names for keys just like SPListItemVersion.

share|improve this answer
    
BeforeProperties didn't work, no change on fields. The other suggestion on Twitter about ItemCheckingIn actually fires after you click OK on the Edit Item page, not before. Thanks for ideas though. –  Anonymous Nov 11 '09 at 6:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.