Hi!
so in the Forms designer you connect to a list and thus you get the fields of the list and can do stuff with them in JS. In my case after I submit my Form the status gets updated and it looks into the "claimvalue" field and checks if that is >= 1000. if it is then xyz
The thing is - the claimvalue field isnt accurate at that time. but the ClaimValue field from another List would be great to look at at that time.
but i cant do fd.field(fieldthatiwant) - i can only select the fields from this list.
can i like, initialize the fields from the other list in JS or something?
Hello @Mart,
Welcome to Plumsail Community!
You can get values from the other list using PnPjs. Please see the code example:
fd.spRendered(function() {
pnp.sp.web.lists.getByTitle('ListName').items.select('Title').get().then(function(items) {
fd.field('Title').value = items[0].Title;
});
});
how can you get the Person field from another List?
Hello @danlim26,
As Person or Group field value is an object, you need to add the expand operator along with select like this:
pnp.sp.web.lists.getByTitle('ListName').items.select('FieldName/Title').expand('FieldName').get().then(function(items) {
//log the display name of the user
console.log(items[0].FieldName.Title)
});
hello, @mnikitina
i need to retrieve some fields from another list, people single and multiple values
pnp.sp.web.lists.getByTitle("ConfigurÄri Subdiviziuni").items.select("Title", "Id","Denumire_x0020_Subdiviziune_x003Id","Manager_x0020_Interimar/Name","Manager_x0020_Notificare/Name",'Manager_x0020_conform_x0020_Func/Name').expand("Manager_x0020_Notificare", "Manager_x0020_conform_x0020_Func",'Manager_x0020_Interimar').filter("Denumire_x0020_Subdiviziune_x003Id eq 440'").get().then(function (results) {
console.log('==========pnp filter============')
//alert(results[0].Denumire_x0020_SubdiviziuneId)// see if we got something
if (results.length > 0) {
// alert(results[0].Title);
var names = [];
var boss=[]
var fin=[]
alert( results[0].Manager_x0020_conform_x0020_Func.Name)
if (results[0].Manager_x0020_conform_x0020_Func.Name){
fin+= boss.push( results[0].Manager_x0020_conform_x0020_Func.Name)
alert('1')}
if (results[0].Manager_x0020_Interimar.Name){
fin+=boss.push( results[0].Manager_x0020_Interimar.Name)
alert('2')}
fd.field('BossLevel1').value=fin
/* results[0].Manager_x0020_Notificare.forEach(function(element) {
fd.field('BossLevel2').value.push(element.Name);
}); */
for(var i = 0; i < results[0].Manager_x0020_Notificare.length; i++){
names.push(results[0].Manager_x0020_Notificare[i].Name);
fd.field('BossLevel2').value=names
alert('names=== '+names)
}
}
})
it works but if the field Manager_x0020_Interimar - is empty - i have an error
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'Name')
at eval (eval at e._executeCustomJavaScript (/_layouts/15/plumsail/forms/widget/spform.js:73), :72:42)
How can i verify blanks values ?
Hello @ixxxl,
You can check whether a column is empty or not by adding a condition as below:
if (results[0].Manager_x0020_Interimar !== undefined) {
console.log(results[0].Manager_x0020_Interimar.Name);
}
Not likely. But you can make sure by testing the code like this:
pnp.sp.web.lists.getByTitle("ConfigurÄri Subdiviziuni").items.select("Title", "Id","Denumire_x0020_Subdiviziune_x003Id","Manager_x0020_Interimar/Name","Manager_x0020_Notificare/Name",'Manager_x0020_conform_x0020_Func/Name').expand("Manager_x0020_Notificare", "Manager_x0020_conform_x0020_Func",'Manager_x0020_Interimar').filter("Denumire_x0020_Subdiviziune_x003Id eq 440'").get().then(function (results) {
console.log(results)
});
@mnikitina
thank you!! the problem was in var fin=+
i make an new variable,and now it works!
pnp.sp.web.lists.getByTitle("ConfigurÄri Subdiviziuni").items.select("Title", "Id","Denumire_x0020_Subdiviziune_x003Id","Manager_x0020_Interimar/Name","Manager_x0020_Notificare/Name",'Manager_x0020_conform_x0020_Func/Name').expand("Manager_x0020_Notificare", "Manager_x0020_conform_x0020_Func",'Manager_x0020_Interimar').filter("Denumire_x0020_Subdiviziune_x003Id eq 440'").get().then(function (results) {
console.log(results)
//alert(results[0].Denumire_x0020_SubdiviziuneId)// see if we got something
if (results.length > 0) {
// alert(results[0].Title);
var names = [];
var boss=[]
var fin=[]
var total=[]
alert( results[0].Manager_x0020_conform_x0020_Func.Name)
if(results[0].Manager_x0020_conform_x0020_Func !== undefined){
boss.push( results[0].Manager_x0020_conform_x0020_Func.Name)
console.log('MaNAGER CONFORM FUNCTIEI======='+results[0].Manager_x0020_conform_x0020_Func.Name)
console.log('fin Manager_x0020_conform_x0020_Func============ '+fin)}
if (results[0].Manager_x0020_Interimar !== undefined){
console.log('INERIMAR ============='+results[0].Manager_x0020_Interimar.Name)
fin.push(results[0].Manager_x0020_Interimar.Name)
alert('fin==Manager_x0020_Interimar========== '+total)
}
total=fin+';'+boss
alert('fin==ALLL========== '+total)
fd.field('BossLevel1').value=total
/* results[0].Manager_x0020_Notificare.forEach(function(element) {
fd.field('BossLevel2').value.push(element.Name);
}); */
for(var i = 0; i < results[0].Manager_x0020_Notificare.length; i++){
names.push(results[0].Manager_x0020_Notificare[i].Name);
fd.field('BossLevel2').value=names
alert('names=== '+names)
}
// var inerimarr=[]
// interimar.push(results[0].Manager_x0020_Interimar.Name)
// alert(interimar)
// alert(results[0].Id);
//save names to a separate array
alert('Good!');
} else {
alert('not good');
}
});