cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Responsive Resident
Responsive Resident

Please help: cannot create a new SharePoint item with patch

Dear all, 

 

I have the following OnSelect function that supposes save all form details to the SharePoint list. Unfortunately, after this function is executed the new item does appear in the SharePoint list even though I get a successful notification message. Could someone please help me find a mistake in the code?

I would like to note that, if I select an existing item in the SharePoint list, edit it, and then use the following OnSelect function to save the updates, the item in the SharePoint list seems to be updated correctly.

 

 

/*set status var*/
Set(
    varStatus,
    "Draft"
);
/*Save form details into a variable varFormData and if the form's mode is New, save as new. If it is not not new update the item.*/
Set(
    varFormData,
    If(
        FormMode = FormMode.New,
        Defaults('Demo Test'),
        SharePointIntegration.Selected
    )
);
/*Patch information that are associated to the forms' instances*/
Patch(
    'Demo Test',
    varFormData,
    form_1.Updates,
    form_2.Updates
);
If(
    IsEmpty(Errors('Demo Test')),
    Notify(
        "Success",
        NotificationType.Success
    );
    Navigate(
        screen_Confirmation,
        ScreenTransition.None
    ),
    Notify(
        First(Errors('Demo Test')).Message,
        NotificationType.Error
    )
)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Responsive Resident
Responsive Resident

found an error in the code:(


instead of FormMode = FormMode.New it has to be to varFormMode = FormMode.New

View solution in original post

6 REPLIES 6
Super User III
Super User III

@mantastg08876 

Not sure that there is any particular problem with your formula.  The only slight change I would make would be to get rid of the extraneous variable, and not sure what varStatus is used for, but I would get rid of that as well.

/*set status var*/
Set(
    varStatus,
    "Draft"
);

/*Patch information that are associated to the forms' instances*/
Patch(
    'Demo Test',
    If(FormMode = FormMode.New, Defaults('Demo Test'), SharePointIntegration.Selected),
    form_1.Updates,
    form_2.Updates
);
If(
    IsEmpty(Errors('Demo Test')),
    Notify(
        "Success",
        NotificationType.Success
    );
    Navigate(
        screen_Confirmation,
        ScreenTransition.None
    ),
    Notify(
        First(Errors('Demo Test')).Message,
        NotificationType.Error
    )
)

However, I would recommend that you utilize a SubmitForm rather than Patch the two forms together as you lose all of the error capabilities of the Form and also many of the built in form validate, error logic, and results.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes , 

 

Thank you. I use varStatus to dynamically change values in Combobox field. I have managed to take advantage of the SubmitForm features by adding the following formula in my other OnSelect formula

 

/*Save form details into a variable varFormData*/
Set(
    varFormData,
    If(
        FormMode = FormMode.New,
        Defaults('Demo Test'),
        SharePointIntegration.Selected
    )
);
/*Validate if all required fields are filled in*/
If(
    form_MaterialRegistration.Valid,
/*set status var*/
    Set(
        varStatus,
        "Technologists"
    );
    
/*Save form details into a variable varFormData*/
Set(
        varFormData,
        If(
            FormMode = FormMode.New,
            Defaults('Demo Test'),
            SharePointIntegration.Selected
        )
    );
    
/*Patch information that are associated to the forms' instances*/
Patch(
        'Material Testing',
        varFormData,
        form_1.Updates,
        form_2.Updates
    );
    If(
        IsEmpty(Errors('Demo Test')),
        Notify(
            "Success",
            NotificationType.Success
        );
        Navigate(screen_Confirmation),
        Notify(
            First(Errors('Demo Test')).Message,
            NotificationType.Error
        )
    ),
    SubmitForm(form_1)
)

 


Ironically, if I get rid of the code and make OnSelect = submitForm(form_1), then SharePoint list item is created as expected. It gets quite puzzling..

Super User III
Super User III

@mantastg08876 

I would go with simple!  This appears quite extensive just to split a form and submit.  You might want to take a look over my video on splitting forms across screen (assuming you are doing this across screens - if this is on a single screen, the solution is even much simpler).  

I am not seeing any real value to Patching and submitting at the same time.  You can avoid the Patch all together and get all the feature of the form back in your hands.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes , noted. However, in my final version, I have 8 screens that all together have around 10 forms. I considered patch would be easier to maintain.. I am not an expert though..

Super User III
Super User III

@mantastg08876 

I would just say - consider the balance.  Your Patch will require more formulas to check for conditions and errors and ultimately will become more difficult to control and maintain than to simply split the forms across the screens and submit One master form (as I highlight in the video).  With that method, there are really only one or two formulas and they are pretty simple ones.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!
Responsive Resident
Responsive Resident

found an error in the code:(


instead of FormMode = FormMode.New it has to be to varFormMode = FormMode.New

View solution in original post

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (64,542)