Update item after it's created from the list or library form

Hello,

I'm trying to use the code below to update a newly created child item using the list or library dialog. However, it seems the dialog is closing before the update can be completed.

Thanks for your help.

fd.spSaved(function (result) {
    // This code is executed after saving the form
    var redirect = result.RedirectUrl;
  result.RedirectUrl = null;
  //Get the saved item ID
var itemId = result.Id;
sessionStorage.setItem('itemId ', itemId );
console.log('New Item Id', itemId);
 //Compose a unique reference
    var poval = 5000 + itemId;
    console.log(poval);
    var siteURL = 'https://test.sharepoint.com/sites/test;
      var web = new Web(siteURL);
      var i = web.lists.getByTitle('Parts').items.getById(itemId).update({
         PO: poval
      }).then(function(){
        console.log("Updated!");
         window.location.href = redirect;
      });
    
});

Dear @aseem,
In general, not a good idea to run this in dialog, it will close before complete. If you're linking items to parent with lookup field, you can use the beforeItemsAttach event to get item IDs - List or Library control — Plumsail SharePoint Forms Documentation

Thanks @Nikita_Kurguzov