Thanks @mnikitina.
When i use debugger, it actually goes into list item update statement with correct Id (result.Id), but the item is not updated.
I wonder, the operation is cancelled by plumsail form before it completes and gets redirected.
I checked, even setTimeout did not work.
It is most likely the form gets redirected without finishing the spSaved function and the list update action is cancelled.
Hi @mnikitina,
No other code other than updating a field in the same list item. It works 7 out of 10 times, randomly fails.
No flow triggered.
Thanks,
Muthu
Hi @Nikita_Kurguzov.
Tried the provided code below but am not getting ProjectID field updated at all. No errors and don't see the console showing "Updated!".
'spSaved' and result object shows in the console before the form is redirected but I don't see 'Updated!' in the console. Any ideas why the ProjectID field is not being updated?
Dear @stormanh,
That means that the default redirect is not disabled as it should be. Which version are you running? SharePoint Online or SharePoint 2019? What's the version of the app package in the app catalog?
Dear @stormanh,
Can you send me a screenshot of the webpart and widget version, in dev tools -> sources?
Also, any errors in browser's console?
As for the code, I've just tested it - works exactly the same as before. Maybe something is wrong with the field that you try to populate? Try this instead:
fd.spSaved(function(result) {
var redirect = result.RedirectUrl;
result.RedirectUrl = null;
console.log('spSaved');
console.log(result);
var siteURL = 'https://abcd.sharepoint.com/sites/ProjectsDashboard';
let web = new Web(siteURL);
const i = web.lists.getByTitle('Projects').items.getById(result.Id).update({
Title: "PROJ" + result.Id
}).then(function(){
console.log("Updated!");
window.location.href = redirect;
});
});
Is there a way to get spSaved to work when a child form is opened in a dialog (from list/library control) and upon it being saved be able to then update the corresponding child item field called "InternalRequest" with the value of a SharePoint calculated field "InternalRequestCalculated" in this child list that was opened and saved in a dialog?
Dear @stormanh,
You can add an event to parent form, and subscribe to either add/edit of the child list:
fd.control('SPDataTable1').$on('change', function(changeData) {
if (changeData.type === 'edit') {
var siteURL = 'https://abcd.sharepoint.com/sites/ProjectsDashboard';
var web = new Web(siteURL);
var i = web.lists.getByTitle('Projects').items.getById(changeData.itemId).update({
Title: "New title " + changeData.itemId
}).then(function(){
console.log("Updated!");
});
}
});
You'll need to do the calculation by yourself in JavaScript though, no calculated fields.
I am actually using the same code you provided - thank you! However, it appears the change event handler of the list/library control doesn't get triggered with this code if the child item of the list/library control is edited (opened in dialog). It gets triggered fine when the child list/library control item is edited inline but not when it's edited in dialog mode. Can you confirm this please, as this is what my tests show.
FYI: I have the list/library control set to inline mode and have a custom button to also allow the child list/library control item to be edited in dialog. It's when I edit the child list/library control item using this custom dialog button that I notice the change event handler of the list/library control doesn't get fired.
Dear @stormanh,
It should work with default dialog mode, but with custom dialog it might not. For custom dialog, you need to use dialog's callback function, an example can be found here - Managing dialog with JS — SharePoint forms