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

View solution in original post

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

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Top Solution Authors
Top Kudoed Authors
Users online (3,477)