Good day .
I have 2 fields(Author and Inlocuitor(people picker, that was introduced in a new form.)
Now in edit i need to get of this users job titles and department from user profile ..
i try this code for Inlocuitor:
fd.spRendered(function(){
function updateUserInfo1() {
//ascund sau arat soldurile de concedii
var employee = fd.field('Inlocuitor').value;
var niv1 = "";
var niv2 = "";
var niv3 = "";
var sec = "";
var tip = "";
//if (employee.length>0){
//console.log(employee.length);
// Popularea cimpului cu Nume Prenume
pnp.sp.profiles.getPropertiesFor(employee.Key).then(function (result) {
var props = result.UserProfileProperties;
for (var i = 0; i < props.length; i++) {
switch (props[i].Key) {
// Sharepoint or AD attribute
case 'DENNIVEL1':
//Form Field Internal name
niv1 = props[i].Value;
break;
case 'DENNIVEL2':
//Form Field Internal name
niv2 = props[i].Value;
break;
case 'DENNIVEL3':
//Form Field Internal name
niv3 = props[i].Value;
break;
break;
case 'TIPSUBUNITATE':
//Form Field Internal name
tip = props[i].Value;
break;
// Sharepoint or AD attribute
/*case 'DEP':
//Form Field Internal name
fd.field('Subdiviziunea').value = props[i].Value;
break;*/
case 'Title':
//Form Field Internal name
fd.field('FunctiaInitiator').value = props[i].Value;
break;
} //switch
} //for
var subdiv = niv1;
if (niv2 != "") {
subdiv += "/" + niv2
}
if (niv3 != "") {
subdiv += "/" + niv3
}
fd.field('SubunitateaInitiator').value = subdiv;
}); //pnp
//}//if
}
updateUserInfo1();
})
Error:
VM8288:68 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')
at eval (eval at e._executeCustomJavaScript (/_layouts/15/plumsail/forms/widget/spform.js:73), :68:35)
I tried in console to check - fd.field('Inlocuitor').value.Key - it return undefined
in other form i used this code and it work, but i manualy put user in field, and put function on change.