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 applied the jslink to the new form of custom list. In that JSLink, I am getting the user profile property and displaying it in label. But I want to blank the text of label when the user name is removed from the people picker control.

My code is:

var userProfileProperty;
var scriptPath = ['/_layouts/15/SP.UserProfiles.js'];      //['/_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 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]);

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();

    document.getElementById('lblDepartmentValue').innerHTML = value;

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

(function () {

    var DepartmentCtx = {};

    DepartmentCtx.Templates = {};
    DepartmentCtx.Templates.Fields = {
        "oiplbDepartment": {
            "NewForm": oiplbDepartment


function oiplbDepartment(ctx) {

    var managerField = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);

    return "<Label ID='lblDepartmentValue'></Label>";

$(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);      

        var finalUserName =

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

        if(loginName == undefined)

    $("input[title='Project Owner']").OnControlResolvedUserChanged(function(){
        alert("Valued Deleted");

After applying the above javascript code I am able to get the user profile property whenver the client people picker control's focusout is fired but I want to hide the label whenver the the entered user is removed from the control.

What should I do?

share|improve this question

Your Answer


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

Browse other questions tagged or ask your own question.