cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
josecardoso
Regular Visitor

Create new record on MySQL table

Hello. Sorry if I'm cross-posting here, but I've been searching and searching all over the forum, and the internet, and I can't find a good solution for doing this. Besides that, I'm very new to Power Automete (Flow), so please forgive me if someone has already posted a solution for this and I couldn't found it.

 

So, basically I'm trying to create a fllow that creates a new record on a MySQL table (connector is working and tested), each time a message is flagged in Outlook. So, I've created a new Flow (Outlook - When a new mail is flagged V3) and then added the action of creating a new row (MySQL Insert Row).

 

As I've read on other forum posts on this forum, for database engines other than MSSQL, I need to create a mandatory Id field, which I was expecting to be automatically filled, as the Id field on the MySQL table is set to INT, Primary Key, Auto Increment ( I can't change this, because the table is part of a self-hosted desktop application.

 

mysql_id.PNG

 

 So, once the Id can't be automatically generated by the flow, how can I get the last Id record from the table and, then, increment by one, using an expression?

 

I've tried using LAST function, based on some suggestions here at the forum, but as I'm a noob with Power Automate, I wasn't able to get it working. Also, I was trying Get Row, but I really can't find a way.

 

Is there anyone who has already have some MySQL new record example working, or Postgres (I think the problem is the same) who can help me here?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
abm
Super User
Super User

Hi @josecardoso 

 

I didn't have MySQL earlier and installed one now. This is what I did to increment the index. Please follow the steps:

My index id column is called idJobTypes which is an auto increment one.

 

image.png

 

Above I did used the Get Rows records top one only order by idJobTypes (Primarykey) desc. This will give you the latest number in the db.

 

Next iterate the result and store in a variable. Finally increment the identifier value and insert the row values using the latest incremented id. See below.

 

image.png

 

The expression I am using above is 

 

add(variables('Id'),1)
 
Below is my test result
 
image.png
 
If you have any questions please let me know.
 
Thanks
Thanks


Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

View solution in original post

2 REPLIES 2
abm
Super User
Super User

Hi @josecardoso 

 

I didn't have MySQL earlier and installed one now. This is what I did to increment the index. Please follow the steps:

My index id column is called idJobTypes which is an auto increment one.

 

image.png

 

Above I did used the Get Rows records top one only order by idJobTypes (Primarykey) desc. This will give you the latest number in the db.

 

Next iterate the result and store in a variable. Finally increment the identifier value and insert the row values using the latest incremented id. See below.

 

image.png

 

The expression I am using above is 

 

add(variables('Id'),1)
 
Below is my test result
 
image.png
 
If you have any questions please let me know.
 
Thanks
Thanks


Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

Many thanks @abm. Perfect, this worked like a charm!

Helpful resources

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

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022- Season 2 has kicked off!

Users online (2,565)