Change values in parent form and call pnp after the save of sub form (child list DT)

Hello what is the best way to do the following:
I need to change values of controls in main form and do PNP to get multiple values from a list and insert the values in main/parent form too.

but i need to do this after save of the child sub form not before save

fd.spBeforeSave(function () {
NOT Here
});

what about :
fd.spSaved(function () {
** is it the best place to do the following:**
pnp.sp.web.lists.getByTitle("List").items.select("Id", "Title", "CtrlName").filter(filter).get().then((rtrnPnp) =>.....
window.top.fd.field('ctrlName01').clear();
window.top.fd.field('ctrlName02').value = rtrnPnp.CtrlName (PNP Result)
});

i tried but i failed
kindly advise

1 Like

Hello @gkhadra,

Sorry for the delay in reply. We had a national holiday.

If you need to run the script after the item is saved, you need to use it under fd.spSaved() event handler. That is right.

But it is not clear for me what you want to perform after the item is saved. Do you want to update the parent form when the child item is saved? Do you want to pass the values from the child element to the parent?

Could you please provide more details and share the code you have. Screenshots of the form would also be helpful.

1 Like

Hello @mnikitina,

Thank you for you reply.
I solved my problem in another way but.

But i am interested to know how to do the following under fd.spSaved() event handler, if you can just give me an example it will help to use this event in another form:

  • How to update the parent form when the child item is save?

  • How to pass the values from the child element to the parent?

is it the same scripts like:
fd.spSaved(function () {
window.top.fd.field('ctrlName01').clear();
window.top.fd.field('ctrlName02').value = fd.field('child control value').value;

Sometimes i will use pnp instead of child control value in order to get data from other list and fill the parent form control
});

What i need to take into consideration to achieve this without errors, do i need to add Settimeout function()
kindly advise

@gkhadra,

You can pass values from the child item, which is opened in the dialog box, to the parent with this code:

window.top.fd.field('ParentTitle').value = fd.field('ChildTitle).value;

And it is up to you, you can either use it under spBeforeSave() or spSaved(). For example:

fd.spSaved(function(spForm) {
var parentForm = window.top.fd;

parentForm.field('TitleParent').value = fd.field('TitleChild').value;

});

You can find more information about event handlers here:
https://plumsail.com/docs/forms-sp/javascript/manager.html#events

Regarding the PNP, it depends on what item you want to return. Please provide more details so we could suggest something.

Hello @mnikitina
I am trying to use the code you provided in a submit button and it does not work. It keeps giving me an error in the console and above the form that it can not "Cannot read property 'field' of undefined."

Both fields are Date and Time.

This is the field from the parent form "Ultima_x0020_dat_x0103_"
This is the field from the child form "Dat_x0103__x0020_sf_x00e2_r_x021"
I even tried to invert them. :slight_smile:

Here is the code:

 fd.spBeforeSave(function(spForm) {
var parentForm = window.top.fd;

parentForm.field('Ultima_x0020_dat_x0103_').value = fd.field('Dat_x0103__x0020_sf_x00e2_r_x021').value;
return fd._vue.$nextTick();
});

return fd.save();

The thing that I'm trying to do is to pass the date from the form that pop-ups from List or Library Control to a date field in the initial form.
Can you please tell me what am I doing wrong?

Thank you!