cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sbgoh
Post Patron
Post Patron

How to detect error for Collect function

Hi,

I wrote a "Collect" function to add a record to the database. May I know how can I detect the function error?

E.g. Collect (datasource, {id:123, status: "New"});

Thanks!

8 REPLIES 8
mdevaney
Super User
Super User

@sbgoh 
Can you please supply a screenshot of the error message you are receiving?  This information always helps when looking for the issue.

 

Additionally, can you please tell me what data type the "status" column in SharePoint (e.g. Text, Number, Choices, etc.)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

GarethPrisk
Resident Rockstar
Resident Rockstar

To be clear here, a Collect function will only store data within the app itself.

You may be looking to perform a Patch function, if you are trying to write data to a data source outside of the app.

In that case, you can use the Errors function to help troubleshoot any issues patching.

 

For example

// Create a New record
Patch(
    dataSource,
    Defaults(dataSource),
    {field: value}
);
// Update an Existing Record
Patch(
    dataSource,
    LookUp(
        dataSource,
        field = filterValue
    ),
    {field: value}
);

@GarethPrisk 
Actually, you can use COLLECT to write to any datasource including SharePoint (the link you sent states that in the subtitle).  Its not as commonly used as PATCH but it works 😉

(opens Mouth) 😮

(inserts Foot) 👣

 

@mdevaneyis correct! It never even occurred to me to use a Collect function that way. 😅

 

Honestly, that seems like a bit of a misleading option by Microsoft. The Patch function works inherently with other important functions like Defaults, Errors, etc. I am very surprised this is an option, given how little value it gives over an explicit create/update action like the Patch function.

Hi @GarethPrisk,

I am creating a record in Microsoft SQL Server DB. I have tried your method but I can't get the success notification even I have successfully created a record in the DB. Below is the format of my code. May I know what went wrong with my code? Thanks in advance.

 

Patch(
dataSource,
Defaults(dataSource),
{field: value}
);
IsEmpty(Errors(dataSource));
	Notify("SR is submitted!", NotificationType.Success);
	Notify("Error in creating SR! " & First(Errors(dataSource)).Message, NotificationType.Error);

 

 

@sbgoh 
Please supply a screenshot of the error message you were receiving.  Its difficult to know what is going wrong without that information.

 

Are you getting the False side of your evaluation; the 'false' Notification?

Hi, I did not get the error message so I suppose the evaluation is true in order to print the success notification. Is there a If else statement for power apps ? I have attached the error.

PA-Submit Error.JPG

 

 

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

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.

Users online (4,824)