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

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
Super User III
Super User III

@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."

Super User II
Super User II

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
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (9,812)