Pnp not working in dialogue form

Hiya Plumsail

We have some code that creates item(s) using data from an Array when a new form is saved.
but we have a problem, when a new form is opened from a dialouge, the item is not created, looking at the network traffic, the request isn't even sent!

the code:

fd.spSaved(function(result) {
    if(ParentItemID && itemClass == 'Child'){
        for (i=0; i<InventorySupplierDetails.length; i++){
            InventorySupplierDetails[i][0].ItemId = result.Id;
            InventorySupplierDetails[i][0].Unique_x0020_Ref = InventorySupplierDetails[i][1] + ':' + result.Id;
            console.log('Inventory Supplier Details...');
            console.log(InventorySupplierDetails[i]);
            pnp.sp.web.getList('/sites/COREaaS-OrderSystem/Lists/Inventory%20 Suppliers').items.add(InventorySupplierDetails[i][0]).then(function(result) {
                console.log(result);
            });
            
        }
    }
});

The code works fine in when the new form is not a dialogue, is this a bug? Additionally, the 2 logs to console are displayed with the correct information, it is just the pnp that isn't run at all...

Please help!

Hello @Jamal_Smith-Graham,

How do you open a form in a dialog?

Are you opening a form in a dialog from List or Library control?

Hiya @mnikitina

It is being opened via a new button on a list/library control.

Hello @Jamal_Smith-Graham,

You can run your code on change event of List or Library control. For instance, like this:

fd.control('SPDataTable1').$on('change', function(changeData) {
    if (changeData.type === 'add') {
        sp.web.lists.getByTitle("List").items.getById(changeData.itemId).update({
                Title: 'new title'
            }).then(function () {

        fd.control('SPDataTable1').refresh();

      });
    }
    
});
1 Like

Thanks @mnikitina that worked perfectly! :slight_smile:

1 Like