Column field not automatic update on user value

Hi, I'm trying to auto display the column details based on your previous script. I'm not sure what should I add in to make it change accordingly once Superior name displayed. The Designation2 column is blank during 1st prefill (based on EmployeeName column), when I manually select Superior column, then only Designation2 is display. Please help me how to auto update this.

Below is the script:

fd.spRendered(function() {

//executes the below steps on field change
fd.field('EmployeeName').$on('change', function(value) {

  //gets properties of the selected user 
  fd.field('Appraisee').value = fd.field('EmployeeName').value.EntityData.AccountName;
  fd.field('ol_Department').value = fd.field('EmployeeName').value.EntityData.Department;
  fd.field('Appraisee').value = fd.field('EmployeeName').value.EntityData.Email;
  //fd.field('UserObjType').value = fd.field('EmployeeName').value.EntityData.PrincipalType;
  //fd.field('UserEmail2').value = fd.field('EmployeeName').value.EntityData.SIPAddress;
  //fd.field('UserID').value = fd.field('EmployeeName').value.EntityData.SPUserID;
  fd.field('Designation').value = fd.field('EmployeeName').value.EntityData.Title;

  //gets manager name of the selected user
  pnp.sp.profiles.getPropertiesFor(fd.field("EmployeeName").value.Key).then(function(result) {
      var props = result.UserProfileProperties;
      for(var i = 0; i < props.length; i++){
        if(props[i].Key == "Manager"){
        fd.field("Superior").value = props[i].Value;
		fd.field("Appraiser").value = props[i].Value;
		//fd.field("HOD").value = props[i].Value;
      break;
        }	
      }
    });

 });
 
//executes the below steps on field change
fd.field('Superior').$on('change', function(value) {

  //gets properties of the selected user 
  //fd.field('Appraisee').value = fd.field('Superior').value.EntityData.AccountName;
  //fd.field('ol_Department').value = fd.field('Superior').value.EntityData.Department;
  //fd.field('Appraisee').value = fd.field('Superior').value.EntityData.Email;
  //fd.field('UserObjType').value = fd.field('Superior').value.EntityData.PrincipalType;
  //fd.field('UserEmail2').value = fd.field('Superior').value.EntityData.SIPAddress;
  //fd.field('UserID').value = fd.field('Superior').value.EntityData.SPUserID;
  fd.field('Designation2').value = fd.field('Superior').value.EntityData.Title;

  //gets manager name of the selected user
  pnp.sp.profiles.getPropertiesFor(fd.field("Superior").value.Key).then(function(result) {
      var props = result.UserProfileProperties;
      for(var i = 0; i < props.length; i++){
        if(props[i].Key == "Manager"){
		fd.field("HOD").value = props[i].Value;
      break;
        }	
      }
    });

 });

});

As the 'Superior' field value set programmatically, not manually, you need to use PNP request to get user information.

For example, the code to get user Job Title and Department will be the following:

//executes the below steps on field change
fd.field('Superior').$on('change', function(value) {

        pnp.sp.profiles.getPropertiesFor(fd.field("Superior").value).then(function(result) {
 			var props = result.UserProfileProperties;
 			for(var i = 0; i < props.length; i++){
     			if(props[i].Key == "Title"){
         			fd.field('Designation2').value = props[i].Value;
         			
     			}
     			else if(props[i].Key == "Department"){
     				fd.field('ol_Department').value = props[i].Value;
         			
     			}
   			}
        });
});

I've tried this code but not working automatically. The field is display only after re-choose the Superior name, otherwise the Designation2 and HOD column are blank.

fd.spRendered(function() {

//executes the below steps on field change
fd.field('EmployeeName').$on('change', function(value) {

  	//gets properties of the selected user 
  	fd.field('Appraisee').value = fd.field('EmployeeName').value.EntityData.AccountName;
  	fd.field('ol_Department').value = fd.field('EmployeeName').value.EntityData.Department;
  	fd.field('Appraisee').value = fd.field('EmployeeName').value.EntityData.Email;
  	fd.field('Designation').value = fd.field('EmployeeName').value.EntityData.Title;

  	//gets manager name of the selected user
  	pnp.sp.profiles.getPropertiesFor(fd.field("EmployeeName").value.Key).then(function(result) {
      	var props = result.UserProfileProperties;
      		for(var i = 0; i < props.length; i++){
        		if(props[i].Key == "Manager"){
        			fd.field("Superior").value = props[i].Value;
					fd.field("Appraiser").value = props[i].Value;
      			break;
        		}	
      		}
    });

});

});

fd.spRendered(function() {

//executes the below steps on field change
fd.field('Superior').$on('change', function(value) {

  	//gets manager name of the selected user
  	pnp.sp.profiles.getPropertiesFor(fd.field("Superior").value.Key).then(function(result) {
      	var props = result.UserProfileProperties;
      		for(var i = 0; i < props.length; i++){
        		if(props[i].Key == "Title"){
     				fd.field('Designation2').value = props[i].Value;	
 				}
 				else if(props[i].Key == "Manager"){
 					fd.field('HOD').value = props[i].Value;		
 				}
      		}
    });

});

});

@noorshahida88,

Please remove Key from this code line:

pnp.sp.profiles.getPropertiesFor(fd.field("Superior").value).then(function(result)

So the code would be as follwos:

fd.field('Superior').$on('change', function(value) {

        pnp.sp.profiles.getPropertiesFor(fd.field("Superior").value).then(function(result) {
 			var props = result.UserProfileProperties;
 			for(var i = 0; i < props.length; i++){
     			if(props[i].Key == "Title"){
         			fd.field('Designation2').value = props[i].Value;
         			
     			}
     			else if(props[i].Key == "Department"){
     				fd.field('ol_Department').value = props[i].Value;
         			
     			}
   			}
        });
});
1 Like

Thanks for helping me @mnikitina :+1:

1 Like