cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jsharkey
Helper II
Helper II

Generating a form ID for SharePoint and patching a single record using submit form and patch()

When I create a new SharePoint custom form app,  I use this to get a new ID:

Set(RObj, Patch(Requests, Defaults(Requests)));

When I'm editing:

Set(RObj, SharePointIntegration.Selected);


I have a form that I am forced to use to save attachments, and I also use a patch function for saving the other fields which span multiple screens. However, for some reason I am creating more than 1 record.

Since pressing "new" from the list automatically generates a new record, I always can just set the form for attachments to edit mode. I set the Item Property of the Attachment Form to:

LookUp(Requests, ID = RObj.ID)

So I'm expecting that executing SubmitForm, should update the record, instead of generate a new one. 


And when I patch I use the following:

Patch(Requests, LookUp(Requests, ID = RObj.ID), {data from other screens})


Why is it creating multiple records? The following is my OnSave Method for the Custom Form.

Patch(
        Requests,
        LookUp(
            Requests,
            ID = RObj.ID
        ),
        {
            StartDate: DateTimeValue(
                Concatenate(
                    Text(dtpStartDate.SelectedDate),
                    ", ",
                    Text(drpStartDateHour.Selected.Value),
                    ":",
                    Text(drpStartDateMin.Selected.Value),
                    " ",
                    Text(drpStartDatePeriod.Selected.Value)
                )
            ),
            EndDate: DateTimeValue(
                Concatenate(
                    Text(dtpEndDate.SelectedDate),
                    ", ",
                    Text(drpEndDateHour.Selected.Value),
                    ":",
                    Text(drpEndDateMin.Selected.Value),
                    " ",
                    Text(drpEndDatePeriod.Selected.Value)
                )
            ),
            'Host Email': txtHostEmail.Text,
            Site: cboSite.Selected,
            Fab: cboFab.Selected,
            Area: drpArea.Selected.Area,
            Department: drpDepartment.Selected.Department,
            'Phone Number': Value(txtPhoneNumber.Text),
            'Number of Visitors': CountRows(PersonGallery.AllItems),
            'Sentry (Gate)': cboSentry.Selected,
            Category: cboCategory.Selected,
            Purpose: drpPurpose.SelectedText.Value,
            ExpressPass: DataCardValue6,
            'Visitation Hours': drpVisitationHours.Selected
        }
    );
    SubmitForm(RequestAttachmentForm);
    RequestHide();



Please do not recommend using the Power Automate Instant Flow method to save attachments. I am more seeking to understand why my approach is not working, or how it could work.

1 ACCEPTED SOLUTION

Accepted Solutions

@Jsharkey ,

The only way I can think of is to do the attachment first by SubmitForm then on the OnSuccess of the form do

Patch(
   Requests,
   {ID:FormName.LastSubmit.ID},
   {Your patch}
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

9 REPLIES 9
WarrenBelz
Super User
Super User

Hi @Jsharkey ,

For a bit of a debugging exercise, put a label on the screen with RobJ.ID and see if it the value you expect.

I was doing that actually, what I'm seeing is that the ID is consistent through the app, but when I save I get three entries with 3 different IDs. 

@Jsharkey ,

Providing RobJ.ID is present and correct, it should Patch the correct record - there is nothing wrong with your syntax, however I will mention the SubmitForm again. Try without this for testing and see if the problem goes away.

The current version of the OnSave method succeeds in only saving one record, resolving the multi-record issue. However, the attachment is not being saved.

OnSave (Some parts removed):

Refresh(Requests);
If(
    IsBlank(GlobalErr),
    Patch(
        Requests,
        LookUp(
            Requests,
            ID = RObj.ID
        ),
        {
            StartDate: DateTimeValue(
                Concatenate(
                    Text(dtpStartDate.SelectedDate),
                    ", ",
                    Text(drpStartDateHour.Selected.Value),
                    ":",
                    Text(drpStartDateMin.Selected.Value),
                    " ",
                    Text(drpStartDatePeriod.Selected.Value)
                )
            ),
            EndDate: DateTimeValue(
                Concatenate(
                    Text(dtpEndDate.SelectedDate),
                    ", ",
                    Text(drpEndDateHour.Selected.Value),
                    ":",
                    Text(drpEndDateMin.Selected.Value),
                    " ",
                    Text(drpEndDatePeriod.Selected.Value)
                )
            ),
            'Host Email': txtHostEmail.Text,
            Site: cboSite.Selected,
            Fab: cboFab.Selected,
            Area: drpArea.Selected.Area,
            Department: drpDepartment.Selected.Department,
            'Phone Number': Value(txtPhoneNumber.Text),
            'Number of Visitors': CountRows(PersonGallery.AllItems),
            'Sentry (Gate)': cboSentry.Selected,
            Category: cboCategory.Selected,
            Purpose: drpPurpose.SelectedText.Value,
            ExpressPass: DataCardValue6,
            'Visitation Hours': drpVisitationHours.Selected
        }
    );
    SubmitForm(RequestAttachmentForm);
    RequestHide();
);


My RequestAttachmentForm only has a single card for attachments, is connected to the Requests DataSource, and has its item set to the same record:

Jsharkey_0-1598449913636.png

 







@Jsharkey ,

The only way I can think of is to do the attachment first by SubmitForm then on the OnSuccess of the form do

Patch(
   Requests,
   {ID:FormName.LastSubmit.ID},
   {Your patch}
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @Jsharkey ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

For clarification:

Are you suggesting that I move the patch function to the OnSuccess function of the attachment form, instead of the OnSave function of the SharePoint Integration?

@Jsharkey ,

Yes - it is a long shot as normally you would simply use SubmitForm for the lot.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Well ---- strangely enough it works.

Putting the Patch function and RequestHide under the Attachment Forms OnSuccess function does the trick.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,980)