SharePoint: Enable “Edit Page” on NewForm.aspx

Thanks to the solution here: http://cakriwut.wordpress.com/2007/11/03/how-to-enable-edit-page-in-sharepoints-standard-formaspx/ I was able to get the “Edit Page” option to appear when adding a new list item.

I needed to do this because I wanted some Javascript to execute on that page to pre-populate some list item values. The script presented here worked great for one value. http://mdablog.spaces.live.com/blog/cns!B0C40902E1212960!473.entry

However, I have multiple querystring values, so I made a small change. (Entire code below, though.)

_spBodyOnLoadFunctionNames.push(“fillDefaultValues”);

function fillDefaultValues() {
var qs = location.search.substring(1, location.search.length);
var args = qs.split(“&”);
var vals = new Object();

for (var i=0; i < args.length; i++) {
//alert(args[i]);
var nameVal = args[i].split(“=”);
var temp = unescape(nameVal[1]).split(‘+’);

nameVal[1] = temp.join(‘ ‘);
vals[nameVal[0]] = nameVal[1];
//alert(‘fillDefaultValues: vals[nameVal[0]]=’ + vals[nameVal[0]] + ‘ nameVal[0]=’ + nameVal[0] );
setValueFromQueryString(nameVal[0], vals[nameVal[0]]);
}

}

function setValueFromQueryString(fieldName, value) {
//alert(‘setValueFromQueryString: fieldName=’ + fieldName + ‘ value=’ + value);
if (value == undefined) return;
var theField = getTagFromIdentifierAndTitle(“input”,”TextField”,fieldName);
if (theField != null) theField.value = value;
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) {
//alert(‘getTagFromIdentifierAndTitle: tagName=’ + tagName + ‘ identifier=’ + identifier + ‘ title=’ + 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)) {
//alert(‘getTagFromIdentifierAndTitle: tags[i].id=’ + tags[i].id + ‘ tags[i].title=’ + tags[i].title + ‘ tags[i]=’ + tags[i]);
return tags[i];
}
}
return null;
}

The final thing I needed to do was add a workflow to the list because I wanted to update another list when an entry was made in this one. This article was a great start: http://blah.winsmarts.com/2006-8-SharePoint_2007__Authoring_custom_workf…

Instead of choosing an email action, I chose to update a list and added the actions to take as shown in the image below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s