Count of filtered items in the Parent Form from Child List in DataTable - not working

In spBeforeSave, I have the following, but i am getting an items is not defined error

var count = fd.control('SPDataTable1).widget.dataItems();

if(count){
for (var i=0; i<count.length; i++){
var dFN = count[i].Field1;

pnp.sp.web.list.getByTitle('ChildList').items.filter("Field1 eq " + dFN + "' and Date eq '09/01/2023').getAll().then(function(item){

  if(item.length> 10) {
        altert("More than 10 items.");
 }

})
return items.length;
);
);
/*** end of spBeforeSave **///

I have added alerts to find out that the error is coming from the pnp statement.

Any help is appreciated.

Thanks

Hello @rhonda,

What is your use case? Why do you run the function inside the spBeforeSave event?

You can disregard this comment. I got it to work properly. Thanks.

1 Like