I have a custom list in which I want to apply the javascript in new form of that list.

Javascript loads the user profile property of the entered user in the people picker control.

I am getting successful output but when I load the page I am getting the below mentioned error in the Internet Explorer's script debugger:

Line: 1647 Error: Sys.InvalidOperationException: Type SP.ULSTraceLevel has already been registered. The type may be defined multiple times or the script file that defines it may have already been loaded. A possible cause is a change of settings during a partial update.

My javascript code is:

var userProfileProperty;
var scriptPath = ['/_layouts/15/sp.js', '/_layouts/15/SP.UserProfiles.js'];
var terms = new Array();
var selectedTermName = "";
var _termLabel = "termName";
var _termId = "termId";
var SspId = "";
var TermsetId = "";
var _type = "type";
var _parentTermId = "parentTermId";
var _parentTermType = "ParentTerm";
var _subTermType = "SubTerm";
function loadUserData(finalUserName) {

    alert("Load User Data");
    //Get Current Context
    var clientContext = new SP.ClientContext.get_current();
    //Get Instance of People Manager Class
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
    //Property to fetch from the User Profile

    var propertyName = "oiplbNativeDepartment";

    //Domain\Username of the user (If you are on SharePoint Online)

    var targetUser = finalUserName;

    //If you are on On-Premise:
    //var targetUser = domain\\username
    //Create new instance of UserProfileProperty
    userProfileProperty = peopleManager.getUserProfilePropertyFor(targetUser, propertyName)
    //Execute the Query. (No load method necessary)
    clientContext.executeQueryAsync(onSuccess, onFail);

function onSuccess() {

    var messageText = "\"Native Department \" property is " + userProfileProperty.get_value();


    var value = userProfileProperty.get_value(); 

function onFail(sender, args) {
    alert("Error: " + args.get_message());
$(document).ready(function () {


    $("input[title='Project Owner']").focusout(function () {


        var loginName = $("span.ms-entity-resolved").attr("ID");      

        var start = loginName.indexOf(":");

        var end = loginName.indexOf("_Processed");

        var finalUserName = loginName.substring(start - 1, end);




function LoadScript() {
    var headTagName = 'head';
    for (count = 0; count < scriptPath.length; count++) {
        var headTag = document.getElementsByTagName(headTagName)[0];
        var scriptTag = document.createElement('script');
        scriptTag.setAttribute('type', 'text/javascript');
        scriptTag.setAttribute('src', scriptPath[count]);

The jquery reference is given to the seattle master page's <head> tag.

What should I do to tackle this error?

  • I did some tricks to find out the statement where the error resides? and got that when I load the sp.js error is thrown otherwise script runs smoothly
    – users1100
    Nov 11 '13 at 6:36

This error shows because SP.js script is loaded twice. First time it is loaded by SharePoint itself, and second time is by you.

You should not load default SharePoint scripts (any scripts, actually) via direct writing to head. SharePoint uses "script on demand" mechanism (SP.SOD), you can read about it here and here.

Shortly, you need to remove LoadScript(); and replace loadUserData(finalUserName); with something like this:

SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function () {
    SP.SOD.executeFunc('userprofile', 'SP.UserProfiles', function () {
  • Thank you for replying sir, I tried your code but it's not working, the function loadUserData() is not being called. I traced it using IE Script debugger.
    – users1100
    Nov 11 '13 at 8:28
  • I'm sorry, my mistake. Fixed it in answer. Look through html in head part of your page, there should be a lot of "RegisterSod(...)" lines. First argument in this function is a name of the script, which should be called via SP.SOD.executeFunc. So we should use userprofile, not SP.UserProfiles.js.
    – zzeneg
    Nov 11 '13 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.