cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Super User
Super User

Re: How to detect error for Collect function

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

Highlighted
Super User
Super User

Re: How to detect error for Collect function

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}
);
Highlighted
Super User
Super User

Re: How to detect error for Collect function

@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 😉

Highlighted
Super User
Super User

Re: How to detect error for Collect function

(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.

Highlighted
Helper V
Helper V

Re: How to detect error for Collect 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);

 

 

Highlighted
Super User
Super User

Re: How to detect error for Collect function

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

 

Highlighted
Super User
Super User

Re: How to detect error for Collect function

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

Highlighted
Helper V
Helper V

Re: How to detect error for Collect function

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
Ignite

Microsoft Ignite

This will be a conference that you do not want to miss!

secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,540)