Call Parent form function from "List or Library" Dialog

Hi Team,

I have Parent form with "List or Library" control in it. Parent form has several JS functions.
A Pop-up window opens to edit the "List or Library" control. When the Status field is changed to "Complete" by user in the Pop-up window and submit, i want to trigger a JS function in Parent form.
How can i achieve this? I have seen articles to access Parent form fields but not Parent form variables or functions.

Thanks,
Muthu

Hello @Muthu,

You can trigger function when the item in List or Library control is changed. To check the status of the changed item use the PnP request. See the code sample.

fd.control('SPDataTable1').$on('change', function(changeData) {
    if (changeData.type === 'edit') {
        console.log(changeData);
        pnp.sp.web.lists.getByTitle('ListName').items.getById(changeData.itemId).get().then(function(i){
            if(i.Status === 'Complete' )[
                //call function
            ]
        })
    }
});

@mnikitina Thank you. Will try that.
Was wondering if there is a way to trigger function in parent form with any pointer/reference to parent from child(pop-up).
Thanks,
Muthu

@Muthu,

Could you please describe the case in more details so I could assist you.

@mnikitina I have a SharePoint Plumsail form with "Reviewer" (Person) field and "List or Library" control linked to "Custom Tasks" list. I like to send notification to Reviewer with some details/fields in parent form when all Tasks are completed (by Assignee of Tasks).
The "List or Library" control is configured to open Pop-up for editing, the Task Assignee will open\edit his Task and mark as Complete. At this stage, i check if all Tasks are complete, then i need to trigger a function in the parent form to send an email with some more field values available in the parent form.
Thanks,
Muthu

@Muthu,

Does user open the task from the parent form?

If so, the method I've shared is suitable for you. You can check weather all related tasks are completed using PnP request.

fd.control('SPDataTable1').$on('change', function(changeData) {
    pnp.sp.web.lists.getByTitle('ListName').items.filter("Parent/Id eq '" + fd.itemId + "'").get().then(function(items){
      var allTasks = items.every(function(i){ 
        return i.Status == 'Completed';
        });
        return allTasks;
    }).then(function(allTasks){
        if(allTasks) {
        //run function
        }
    });
});

Use the fields internal name in the code instead of Status, Parent.

@mnikitina Yes, user open the task from the parent form.

Will implemente as you suggested.
Many thanks.

1 Like

@Muthu,

I had a similar need. I created a Common field on my parent form, then used dialog returnedArgs to set the Common field. In the parent form I used on change event to initiate the function.

Just a thought.

@cwalter2 Thanks for your input.
I dont use Dialog to open the pop-up, instead i use "List or Library" control's in-built pop-up to edit the item.
Will it return returnedArgs? Can you please share a code snippet in the parent form where you read and set the common field.

Thanks very much.

@Muthu,

You will need to create custom button on your list/library control:

Here is what I did on the parent form, all in spRendered:

var submittalNew = {
    text: 'Log Submiital',
    class: 'btn-primary',
    visible: true,
    icon: 'Add',
    iconType: 0,
    click: function () {
        var url = 'https://mysite.sharepoint.com/sites/pwa/SitePages/PlumsailForms/Project%20Submittals/Item/NewForm.aspx';
        var url2 = 'https://mysite.sharepoint.com/sites/pwa/SitePages/PlumsailForms/Project%20Submittals/Item/EditForm.aspx?item=';
        Dialog.open(url,
            {argsId: fd.itemId},
            function(hasSaved, returnedArgs) {
                if(hasSaved){
                    fd.control('Submittals').refresh()
                    fd.field('SingleLineText5').value = url2 + returnedArgs.ID;
                } else {
                    alert('Form closed without Saving');
                }
            }, {width: scrWidth, heigh: scrHeight});
    }
};

The SinlgeLineText5 common field is what I monitor for change with:

fd.field('SingleLineText5').$on('change', openDia);

Then the openDia function is:

function openDia () {
scrWidth = Number(window.innerWidth) * .75
scrHeight = Number(window.innerHeight) * .75
Dialog.open(fd.field('SingleLineText5').value,
    {args: 'Sometheing'},
    function(hasSaved) {
        console.log(hasSaved)
    }, {width: scrWidth, height: scrHeight});
}

On the child form this is the complete code I have in spSaved:

fd.spSaved(function(result) {
    if (window.frameElement && Dialog.getArgs()){
        Dialog.close(true, {ID: result.Id });
    }
});

@cwalter2 Got it.
Thanks very much for the detailed code, very much appreciated.
I will try this.

Best regards,
Muthu