Problem with multiple HTML properties in user profile

Recently I was configuring user profiles in SharePoint 2013 and I had to add several custom user properties including html fields. All other properties worked find except html ones. Html properties showed up fine on edit profile page, I entered text and saved the profile, but when I opened my profile again for edit only the last property had value and others where empty. After some investigation I figured out that the EditProfile.aspx in 15 hive had JavaScript which can’t fill in multiple html properties, it’s a bug which has not been fixed until December 2013.

I had three properties on the page, biography, qualifications and expertise, as in the picture below

UserPropHTML

EditProfile.aspx contains the values of properties in hidden fields as;

<input name="ProfileEditorEditBiography_hiddenRTEField" id="ProfileEditorEditBiography_hiddenRTEField" type="hidden" value="Bio"/>


<input name="ProfileEditorEditQualifications_hiddenRTEField" id="ProfileEditorEditQualifications_hiddenRTEField" type="hidden" value="Qualification"/>

<input name="ProfileEditorEditExperties_hiddenRTEField" id="ProfileEditorEditExperties_hiddenRTEField" type="hidden" value="Skills and stuff"/>

The JavaScript code the edit profile page generates to fill the properties is

userprophtmlcode

The problem in the above code is obvious, it has three functions which are supposed to set values in biography, qualification and expertise fields, but all three functions have the same name. When they get pushed into _spBodyOnLoadFunctionNames, the second push call overwrites the first one and the third push overwrites the second function in the stack, leaving only the last function in the stack to be called.

The solution was to modify this page, and add my own javascript code, which would set proper values to proper fields.

Here’s the code I added inside AdditionalPageHead to fix the problem.

<script type="text/javascript">

_spBodyOnLoadFunctionNames.push('RePopulateEditableRegion');

function RePopulateEditableRegion(){

// SETTING BIOGRAPHY PROPERTY VALUE
var editableRegion = document.querySelector('[InputFieldId=ProfileEditorEditBiography_hiddenRTEField]');
if (editableRegion) {
var field = document.getElementById("ProfileEditorEditBiography_hiddenRTEField");
    if (field) {
editableRegion.innerHTML = field.value;
}
}

// SETTING QUALIFICATIONS PROPERTY VALUE
editableRegion = document.querySelector('[InputFieldId=ProfileEditorEditQualifications_hiddenRTEField');
    if (editableRegion) {
var field = document.getElementById("ProfileEditorEditQualifications_hiddenRTEField");
        if (field) {
editableRegion.innerHTML = field.value;
}
}

// SETTING QUALIFICATIONS PROPERTY VALUE
editableRegion = document.querySelector('[InputFieldId=ProfileEditorEditExperties_hiddenRTEField]');
if (editableRegion) {
var field = document.getElementById("ProfileEditorEditExperties_hiddenRTEField");
    if (field) {
editableRegion.innerHTML = field.value;
}
}
}

</script>
I will have to keep an eye when this bug is fixed in future updates, if the fix is only the server side, then I will have to remove my javascript and if the fix replaces EditProfile.aspx, then I won’t have to do anything.

Advertisements
  1. #1 by lighty37 on April 10, 2014 - 3:31 pm

    I did the problem with you, you rock guyss :thumbup:

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: