K, I dont know if there is one integreated in SharePoint already but here how
I did it with some of my InfoPath form.
In your form, create 2 variable
One for the ID one for a Status because you dont want that everytime you
open the form the ID change, only when its a new opened form.
In your Sharepoint Form Library, create a Column (you can hide it after so
its not show in the default view) that will keep the ID, you can name it
whatever you want, "IDForm".
In you Infopath form, create a connection that will look at that column.
In your rule when form in opened, check if there is a field in "IDForm" that
look like /d/d/d/d (Just for demo, this mean that the ID have 4 numbers).
This will be used to know if you already have at least 1 document in you
documents library. If no and Status=0 (new form), you now put a value for the
first ID. Like 1000. And then you change status form 0(new form) to
1(openedform) (can be what you want).
Add a second rule, if /d/d/d/d exist and status=0 then the ID of your new
form will be ID= max(@IDForm)+1 and again you dont forget to change status to
1. (So your second form will have ID = (1000)+1 = 1001 and so on.
Now you need to submit the form and link the field ID of your Infopath form
to the IDForm of your column.
Dont forget Status, because otherwise everytime you will open the same form,
it will overwrite the ID.
Also check the stop rule in each of your 2 rules.