Redirect to EditForm from NewForm in dialog

Is it possible when saving a new form in dialog to redirect to the edit form in dialog? I used to be able to do this with the Dialog.open command but somewhere along the line it started giving me a map error when trying to save and the page locks up, even if I hit close the page is locked. Using the result.RedirectUrl does not do anything and does not pass an error in the console log so I assume this is due to the dialog.

Here is my code:

> fd.spSaved(function(result) {
>     //var listId = fd.spFormCtx.ListAttributes.Id;
>     var itemId = result.Id;
>     var scrWidth = Number(screen.width) * .75
>     var scrHeight = Number(screen.height) * .75
>     //replace "https://domain.sharepoint.com/sites/sitename/subsite" with path to your site
>     //PageType=6 means Edit Form
>     Dialog.open("https://hrmech.sharepoint.com/sites/pwa/SitePages/PlumsailForms/Drawing%20Log/Item/EditForm.aspx?item=" + itemId, { }, { }, { width: scrWidth, height: scrHeight });
> });

Hello @cwalter2,

How do you open a form in a dialog? Do you open it from the List or Library control?

Yes, I open the NewForm in Dialog from a List or Library Control.

@cwalter2,

You can try out this code on the parent form to open the dialog when a new item is created:

fd.control('SPDataTable1').$on('change', function(changeData) {
    if (changeData.type === 'add') {
        Dialog.open("https://hrmech.sharepoint.com/sites/pwa/SitePages/PlumsailForms/Drawing%20Log/Item/EditForm.aspx?item=" + changeData.itemId.ID, { }, { }, { width: 400, height: 400 });
    }
});

I had to modify the code slightly:
+ changeData.itemId, { }, ....
I am getting the following error in console:


Everything appears to be operating correctly but I have not been able to extensively test.

@cwalter2,

This error is not related to the code I've shared.

Why you've had to modify the code? Were you getting errors when using changeData.itemId.ID?

It did not work using changeData.itemId.ID

@Margo Hi :slight_smile: Can you please help me - i have exactly the same case, I followed the steps -> new forms saves and -> redirects to edit in dialogue (perfect!) but after that, I cannot save or even close the Edit form in dialogue, I have this error on the dialogue screen:
09-05-2024 11-14-13 PM
Adding your code does not do anything good or bad. What is missing here? I copied the script above, just put my link.

Hello @katy,

Try adding the setTimeout() function to essure that the New form dialog is closed before opening the dialog with Edit form.
Update the control name and URL in the code before testing:

fd.control('SPDataTable1').$on('change', function(changeData) {
    if (changeData.type === 'add') {
        var newItemID = changeData.itemId;
        setTimeout(function(){
            Dialog.open('https://domain.sharepoint.com/sites/sitename/subsite/SitePages/PlumsailForms/ListName/ContentType/EditForm.aspx?item=' + newItemID,
            { args: 'something' }, function(hasSaved) {
                if(hasSaved){
                    alert('Form in dialog has saved and closed.');
                }
                else{
                    alert('Dialog form was closed without saving!');
                }
                }, { width: 600, height: 600  });
            }, 3000);
    }
});

Sorry @Margo , still doing nothing, but i see that alerts are not coming as well so there must be something not right. Should I change { args: 'something' } to anything?

@katy,

Please export the form and share it. I will review the form and the code.

@Margo Thank you! I sent you a message with the attached forms.

Hello @katy,

Thank you for the forms!

The code for the dialog is outside of the spRendered() function. Please update the code:

fd.spRendered(function() {
    
    fd.control('PartInfo').$on('change', function(changeData) {
        if (changeData.type === 'add') {
            var newItemID = changeData.itemId;
            setTimeout(function(){
                Dialog.open("https://linamarcorporation.sharepoint.com/sites/SupplierNomination/PartDetails/Item/EditForm.aspx?item=" + newItemID,
                { args: 'something' }, function(hasSaved) {
                    if(hasSaved){
                        alert('Form in dialog has saved and closed.');
                    }
                    else{
                        alert('Dialog form was closed without saving!');
                    }
                    }, { width: 600, height: 1600 });
                }, 3000);
        }
    });

});

@Margo a little progress - something is opening, but not the edit form :slight_smile:
getting this 404 page:


and this code in the console:
09-10-2024 8-10-02 AM

@katy,

Please try updating the url like so:

https://linamarcorporation.sharepoint.com/sites/SupplierNomination/SitePages/PlumsailForms/PartDetails/Item/EditForm.aspx?item=

@Margo awesome! that helps! there is only one tiny thing - is it possible instead of dimensions for opening the form ({ width: 600, height: 600 }) specify to open it in full screen? Something like in the initial code ( var scrWidth = Number(screen.width) * .75) not *.75 -> 1 ?

@katy,

You can do that like this:

{ width: window.screen.width, height: window.screen.height }

@Margo Great!!!! Thank you soooooooooooo much, Margarita! You are the best!

1 Like