cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PytByt
Level 8

Capture app notification in collection

Hi all..

 

I want to log every notification that came out of my app. And create collection for it, and show it in a data table.

 

For example,
Assume that i have multiple notification when the user load master data:

If(CountRows(ProductTranslationColl1)=2000, Notify("Error, only 2000 Product translation Iter 1 have been loaded. Contact IT team.", NotificationType.Error));

If(CountRows(ProductTranslationColl2)=2000, Notify("Error, only 2000 Product translation Iter 2 have been loaded. Contact IT team.", NotificationType.Error));

If(CountRows(ProductTranslationColl3)=2000, Notify("Error, only 2000 Product translation Iter 3 have been loaded. Contact IT team.", NotificationType.Error));

If(CountRows(ProductTranslationColl4)=2000, Notify("Error, only 2000 Product translation Iter 4 have been loaded. Contact IT team.", NotificationType.Error));

If(CountRows(ProductTranslationColl5)=2000, Notify("Error, only 2000 Product translation Iter 5 have been loaded. Contact IT team.", NotificationType.Error));

If(CountRows(ProductTranslationColl6)=2000, Notify("Error, only 2000 Product translation Iter 6 have been loaded. Contact IT team.", NotificationType.Error));

If(CountRows(ProductTranslationColl7)=2000, Notify("Error, only 2000 Product translation Iter 7 have been loaded. Contact IT team.", NotificationType.Error));

Now, what i need to achieve is capture all notification that appears in the app screen and store it in a collection. 
Is this possible to achieve in powerapps?
How can i do this?

Please help.

Regards.
pytbyt

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Capture app notification in collection

That depends.  The way your initial post shows the set of errors, it appears you could have multiple errors generated because each IF is executed and has the potential to generate an error.  If that is the case, if you used a variable, you could overwrite the values set by the first message with a second error message and you would lose it. 

 

So, if multiple If's may be true, I would just include within the existing IF clauses.  

If only one If will be true out of the list of 7 you gave in your first post, I would consider restructuring to be a single IF statement to make it clear that only 1 is possible, and then, yes you could use variables for both message and type like:
Set(ErrMsg, ""); Set(ErrType, "");

If(CountRows(ProductTranslationColl1)=2000, Set(ErrMsg, "Error, only 2000 Product translation Iter 1 have been loaded. Contact IT team."); Set(ErrType, "Error"),Notify(ErrMsg, ErrType), CountRows(ProductTranslationColl2)=2000, Set(ErrMsg, "Error, only 2000 Product translation Iter 2 have been loaded. Contact IT team."); Set(ErrType, "Error"),Notify(ErrMsg, ErrType),<repeat for other errors...));

If(!IsBlank(ErrMsg), 

Patch(NotificationLog, Defaults(NotificationLog), {AppUserEmail: CurrentUserEmail, MsgDateTime: Now(), MsgText: ErrMsg, MsgType: ErrType});Set(ErrMsg, ""))

 

Note: it isn't required to restructure into a single IF, it is just the way I would do it to make it clear that only one of those can be true at a time.  You could still leave it as it is and have one patch at the end as long as YOU are absolutely sure that you will only have 1 of those errors.  Otherwise, you could lose errors by overwriting the values you set from one error with a subsequent error.

View solution in original post

10 REPLIES 10
Super User
Super User

Re: Capture app notification in collection

You would need to create a Notifications collection, then use Patch to write a record to the collection every time you issue a notification. The syntax of the Patch command would be:

Patch(colNotifications, Defaults(colNotifications), {columnName: data to store, columnName: data to store})

Before your application closes, you would need to write the collection to a permanent data store if you plan to keep it beyond the current user session. 

 

More Information on Patch

PytByt
Level 8

Re: Capture app notification in collection

Hi @LRVinNC 

Thank you for your reply.

I still dont know how i can capture the notification it self.
The notification i meant is the notification that appear on the top of the screen of the app.

I'm new to powerapp and i dont have advance skill in programming, i'm sorry for this inconvenient. But, can you help me achieve your solution for my problem?

Regards.
pytbyt

Super User
Super User

Re: Capture app notification in collection

You can't directly "capture" the notify messages.  But since you are the one writing them to begin with you can also write a copy of the same message to a collection or file.

 

A few questions:

1.  Are you wanting to save the set of errors to a file you can retrieve later and if so, what data store are you going to use - Sharepoint?

2.  In addition to the error message, what pieces of information are you wanting to save?  Date/time of the error and the identity of the user who got the error?  Anything else?

 

With these answers, I'll try to give you a little more guidance to get you started.

PytByt
Level 8

Re: Capture app notification in collection

Hi @LRVinNC 

Sorry for my late reply.

Yes please, i need your help.

1.  Are you wanting to save the set of errors to a file you can retrieve later and if so, what data store are you going to use - Sharepoint?
Yes, i think about either sharepoint or CDS

2.  In addition to the error message, what pieces of information are you wanting to save?  Date/time of the error and the identity of the user who got the error?  Anything else?
Yes, i want to save it all.. time stamp, the user using the app, the error message and also all notification message

I looking forward for guidance.

Thank you.

pytbyt


Edit:
This is the kind of notification that i want to capture/save/store in the collection:
notif1.pngnotif2.png
With the time stamp and user that using the app, etc. 

Please help...

Regards.

Super User
Super User

Re: Capture app notification in collection

You will only be able to record any messages that you are generating via a Notify statement.  If the system has automatically issued some type of notification that you didn't specifically tell it to issue, you won't be able to record that. Basically, every time you use Notify to send a message to the user, you must at the same time write a copy of that message to a collection or file.

 

Since you want to save this, I suggest going directly to a sharepoint list, rather than collection.  That will commit your changes and prevent the data being lost of the user suddenly shuts off the app or closes the tab.  (I don't use CDS so I can't advise you on using it).

 

1.  Create a Sharepoint list (NotificationLog) containing the information you are going to log.  I think the only things you are going to be able to record are user, date/time, the message you are writing out and the type of message (Error, warning, success or information) so create 4 columns.  I recommend making the default Title column a non-required field in your Sharepoint list so you can create your own 4 columns.  I'm going to assume there were 4 new fields created (AppUserEmail (text, not person), MsgDateTime (date), MsgText (text), and MsgType (text) and that Title has been made non-required.  If you do it different, you'll need to adjust below.

2.  Add NotificationLog as a data source for your app.

3.  In your App - OnStart property include:
     Set(CurrentUserEmail, User().Email);

4.  Everywhere you use Notify, also include a second statement to write the message to the sharepoint list:

     Patch(NotificationLog, Defaults(NotificationLog), {AppUserEmail: CurrentUserEmail, MsgDateTime: Now(), MsgText: "<put the same text you use in the notify here in quotes>", MsgType: "<one of the 4 types of message - Error, Warning, Success, Information in quotes">})

 

This should record a copy of each message you sending the user on the screen.  As I said, there is no way to capture a system generated message (one you did not request with a Notify) that I am aware of.

PytByt
Level 8

Re: Capture app notification in collection

Hi @LRVinNC 

Thank you for your explanation, I will try it out.

Just one more thing, can use variables to get my copy of notification message? How?

Thanks.

Regards.

pytbyt

Super User
Super User

Re: Capture app notification in collection

You could create a variable for this but I don't think it gains you anything since you would only be using it for the notify and patch like this:


If(CountRows(ProductTranslationColl1)=2000, Notify("Error, only 2000 Product translation Iter 1 have been loaded. Contact IT team.", NotificationType.Error);Patch(NotificationLog, Defaults(NotificationLog), {AppUserEmail: CurrentUserEmail, MsgDateTime: Now(), MsgText: "Error, only 2000 Product translation Iter 1 have been loaded. Contact IT team.", MsgType: "Error"}));

PytByt
Level 8

Re: Capture app notification in collection

Is it mean that i patch Everytime i have the error messages?

I mean, i put the patch formula right after each error messages formula?
Super User
Super User

Re: Capture app notification in collection

That depends.  The way your initial post shows the set of errors, it appears you could have multiple errors generated because each IF is executed and has the potential to generate an error.  If that is the case, if you used a variable, you could overwrite the values set by the first message with a second error message and you would lose it. 

 

So, if multiple If's may be true, I would just include within the existing IF clauses.  

If only one If will be true out of the list of 7 you gave in your first post, I would consider restructuring to be a single IF statement to make it clear that only 1 is possible, and then, yes you could use variables for both message and type like:
Set(ErrMsg, ""); Set(ErrType, "");

If(CountRows(ProductTranslationColl1)=2000, Set(ErrMsg, "Error, only 2000 Product translation Iter 1 have been loaded. Contact IT team."); Set(ErrType, "Error"),Notify(ErrMsg, ErrType), CountRows(ProductTranslationColl2)=2000, Set(ErrMsg, "Error, only 2000 Product translation Iter 2 have been loaded. Contact IT team."); Set(ErrType, "Error"),Notify(ErrMsg, ErrType),<repeat for other errors...));

If(!IsBlank(ErrMsg), 

Patch(NotificationLog, Defaults(NotificationLog), {AppUserEmail: CurrentUserEmail, MsgDateTime: Now(), MsgText: ErrMsg, MsgType: ErrType});Set(ErrMsg, ""))

 

Note: it isn't required to restructure into a single IF, it is just the way I would do it to make it clear that only one of those can be true at a time.  You could still leave it as it is and have one patch at the end as long as YOU are absolutely sure that you will only have 1 of those errors.  Otherwise, you could lose errors by overwriting the values you set from one error with a subsequent error.

View solution in original post

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

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