1

We have some javascript on a Workflow Task EditForm which upon changing a drop dowm menu would set the value on a PeoplePicker field. This worked for a long time, but something has happened - possibly since our CU upgrade and we are now getting an error (Seen in IE Developer tools) on this line:

var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id];

The error is "Unable to get property 'id' of undefined or null reference".

Here is the full code added on the page - through a Custom Editor WebPart link:

<script type="text/javascript">
    $(document).ready(function () {

        hideColumn("Content Type","true");        
        $('[id^="Title_"]').attr('disabled', true);
        $('[id^="Body_"]').attr('disabled', true);
        $('[id^="DueDate_"]').attr('disabled', true);                
        $('[id^="Status_"]').val('Completed');
        hideColumn("Task Status","true");
        hideColumn("Due Date","true");
        //hideColumn("Description","true");

        var stakeholderKey="stakeholder review task";
        var ownerKey="policies and procedures review task";
        var leadKey="lead task";

        // Stakeholder Review
        if($("[id$='ContentTypeChoice'] option:selected").text().toLowerCase().indexOf(stakeholderKey)>=0)
        {   
            // UI logic here for stakeholders review

        }
        else if($("[id$='ContentTypeChoice'] option:selected").text().toLowerCase().indexOf(ownerKey)>=0)
        {
            SubmitTocontrol("Review_x0020_Outcome_","ready for approval");  

        }
        else if($("[id$='ContentTypeChoice'] option:selected").text().toLowerCase().indexOf(leadKey)>=0)
        {
            SubmitTocontrol("Lead_x0020_Outcome_","ready for owner approval");

        }
    });

    function SubmitTocontrol(controlObjID,conditionStr)
    {
        $('[id^='+controlObjID+']').change(function(e) { 
            var changedValue=$("[id^="+controlObjID+"] option:selected").text().toLowerCase();

            if (changedValue==conditionStr)
            {
                SetPeoplePickerValue("Submit To","ourdomain\\sps_workflow");
                hideColumn("Submit To","true");
                alert("Test D");
            }
            else
            {
                SetPeoplePickerValue("Submit To","");                   
                hideColumn("Submit To","false");
                alert("Test E");
            }
        });     
    }

    function SetPeoplePickerValue(fieldName, userAccountName) {
        var peoplePickerDiv = $("[id$='ClientPeoplePicker'][title='" + fieldName + "']");
        var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id];
        if (spPeoplePicker.GetAllUserInfo().length == 0) 
        {
            var peoplePickerEditor = peoplePickerDiv.find("[title='" + fieldName + "']");
            peoplePickerEditor.val(userAccountName);
            spPeoplePicker.AddUnresolvedUserFromEditor(true);
        }
        else
        {
            $("[id$='_ResolvedList']").html("");
            $("[id$='ClientPeoplePicker_HiddenInput']").val("");
        }
    }   

    function hideColumn(c,control) {
        if(control=="true")
        {
            $(".ms-formlabel h3 nobr").filter(function () {
                var thisText = $.trim($(this).clone().children().remove().end().text());
                return thisText.indexOf(c) === 0 && thisText.length === c.length;
            }).closest("tr").hide();
            $(".ms-formlabel h3").filter(function () {
                var thisText = $.trim($(this).clone().children().remove().end().text());
                return thisText.indexOf(c) === 0 && thisText.length === c.length;
            }).closest("tr").hide();
        }
        else
        {
            $(".ms-formlabel h3 nobr").filter(function () {
                var thisText = $.trim($(this).clone().children().remove().end().text());
                return thisText.indexOf(c) === 0 && thisText.length === c.length;
            }).closest("tr").show();
            $(".ms-formlabel h3").filter(function () {
                var thisText = $.trim($(this).clone().children().remove().end().text());
                return thisText.indexOf(c) === 0 && thisText.length === c.length;
            }).closest("tr").show();
        }
    }

Your Answer

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

Browse other questions tagged or ask your own question.