Hi all,
I would really appreciate any advice regarding the following situation:
I have customised a SharePoint form with canvas apps and ended up having several forms that are submitted at different stages of the data entry process. Everything seems to be working as expected, except that in one process step I am not able to update an existing record in the SharePoint list. I am using the following "Save draft" button's OnSelect function to save data to the SharePoint:
/*set status variable that aumatically selects DefaultSelected value in the ABC status dropdown*/
Set(
varStatus,
"Draft"
);
/*Save form details into a variable varFormData so that I can patch items from other forms to it*/
Set(
varFormData,
If(
varFormMode = FormMode.New,
Defaults(ABC),
SharePointIntegration.Selected)
);
/*
I initiate varFormMode with OnView, OnNew, OnEdit Sharepoint integrations and use that variable in forms' ITEMS property, as such:
If(varFormMode = FormMode.New, Defaults(ABC), SharePointIntegration.Selected)
/*
/*Patch information that are associated to the forms' instances*/
Patch(
ABC,
varFormData,
form_1.Updates, //FormMode = New. User inputs data manually in this form
form_2.Updates, //FormMode = New. Data updated automatically based in inputs in form 1
form_3.Updates, //FormMode = New
form_Attachments.Updates //FormMode = New
);
/*Show notification messages to inform the user about operations without closing the canvas app, so that they could finish editing the form after saving a draft version of it*/
If(
IsEmpty(Errors(ABC)),
Notify(
"Success. Your updates have been saved. You can continue editing the protocol or close it.",
NotificationType.Success
)
,
Notify(
First(Errors(ABC)).Message,
NotificationType.Error
)
)
When the function above is executed, the new record is created in the SharePoint list. When the function is executed again while editing the same form, the new record is created again with duplicate information. However, the ideal scenario would be:
1. User edits canvas app form
2. User clicks the "Save draft" button to save the progress and to create the item in the SharePoint list
3. User continues editing the form and clicks the "Save draft" button again
4. Result: the existing record in the SharePoint list is updated.
By the way, when the "Save draft" is clicked and the function above is executed, all forms remain in the New mode in an attempt to allow users to continue editing the form. I have tried changing the forms to the Edit mode after the "Save draft" button is clicked but that didn't help - the new record is created and the button with the function above is clicked.
Perhaps someone could help to troubleshoot, where could be the problem and why that function creates a new SharePoint list record instead of updating an existing one? Would sincerely appreciate any advice.