Form not always opening in Panel

Hi there,

I have an issue with a New form i have set to be open in a Panel.
The form does not always open in Panel. It seems to have to do with the page not fully loaded.
Anyone experiencing the same?

I wouldnt care if the form doesnt open in a panel if some custom code on the spSaved event worked.
After the item is saved, i grab the item Id and create 3 items in a different list which have a lookup field set to the Id of the newly created item.

Interestingly, this only works if the form opens in a Panel. Weird? uh?

Any help appreciated.

Hello @Pablo_Medina,

Welcome to Plumsail Community!

Yes, the page must be fully loaded in order for the user to open the form in the panel.

It is strange that the code only works when the form is opened in the panel.
Could you please share the code that you are using.

Hi @mnikitina,

Thanks for checking. In a nutshell, what i need to do is to create 3 items in a different list with a lookup set to the item ID I save in the current form. My guess is that this is some kind of timing issue.

This is the code:

    fd.spSaved(function(result){
    console.log(result);
    // listId
    var listId = fd.spFormCtx.ListAttributes.Id;
    // saved item 
    var createdItemId = result.Id;
    doCreateChangePeriods(createdItemId);
    // not working if form opens in a panel
    //result.RedirectUrl =
    //    "https://swarovski.sharepoint.com/sites/202908/_layouts/15/listform.aspx?PageType=4&ListId="
    //    + listId + "&ID=" + createdItemId;

});

function doCreateChangePeriods(relatedEPOChangelogId){
    var promises = [];
    ["DEV", "QA", "PROD"].map(function(period){
        promises.push(createChangePeriod(period, relatedEPOChangelogId));
    });
    Promise.all(promises)
    .then(function(results){
        console.log(results);
    })
    .catch(function(error){
        console.log("TODO: rollback created item? "+error);
        alert("Error while creating Change periods. Try again later.")
    });
}

function createChangePeriod(type, relatedEPOChangeId){
    return pnp.sp.web.lists.getByTitle("Change Periods").items.add({
        'Title': type,
        'Related_x0020_Change_x0020_logId': relatedEPOChangeId,
        'Status': type
    }) 
}

Dear @Pablo_Medina,
What if you try to add the following line inside fd.spSaved:

fd.spSaved(function(result) {
    result.RedirectUrl = null;
    ...

This will prevent redirection after save. Then, you can manually redirect with the following code:

    Promise.all(promises)
    .then(function(results){
        console.log(results);
        if(!fd.isPanel){
            window.location.href = 'URL of the page to redirect to'
        }
    })
1 Like

Thanks @Nikita_Kurguzov, i will give it a try and let you know.
Cheers!

Hi @Nikita_Kurguzov,

got it working as suggested. Thanks for your help!

2 Likes