Retrieve Identity not working for MS SQL and Node

This is the response:
image

Hey Patrick, were you able to find out anything on this?

Until now nothing. It should return the identity correctly. Which version of SQL server are you using exactly?

The project I have tried it on is MS SQL Server 2017. It works without issue using Classic ASP and ASP.NET but when connecting to the same table, same Server Action steps in Node, it does not return identity.

@patrick, I hate to keep asking about this, but I’m at a stand still. We’ve been back and forth for a week now with no resolve or advice. At this point, I either need to find out what I’m doing wrong, find a work-around, or abandon Node as my project framework and go back to ASP.NET which will require a lot of extra work on my part.

You can try the following, edit the file lib/core/db.js.

Line 76 looks like:

if (ast.type == 'insert' && ast.returning && this.client.config.client == 'postgres') {

Change it to:

if (ast.type == 'insert' && ast.returning) {

In you server connect action json file find the options for the insert step:

        "options": {
          "connection": "Target",
          "sql": {
            "type": "insert",
            "values": [
              {

Add an extra property to it:

        "options": {
          "connection": "Target",
          "sql": {
            "type": "insert",
            "returning": "AppointmentID",
            "values": [
              {

Check if it now returns the id.

1 Like

Yes Patrick, that worked thank you. It even worked better than expected because it returns the GUID identity in my database, and all the other times I’ve used it in ASP.NET I believe it returns the incrementing number identity. It never worked with the GUID, so I had to add the incrementing identity,. This way, I can continue to use my GUID PK. Thank you again.

Will this be included in the next update?

I will apply the changes in the db.js file for the next update.

1 Like

This seems to be broken for me in 3.5.7 using Node.js and SQL Server

Last week I updated Wappler to 3.5.7. Tonight for the first time since the update I had to make a change to the site that only involved some html and when I saved the changes, Wappler updated all the other related updated Server Connect files. When i logged in to the app, I started getting errors. Retrieve Identity no longer works in Node.js and SQL Server. I have not made any changes to the server connect files.

Which version of SQL server do you use?

If you undo the change, does it then work again?

edit the file lib/core/db.js .

Line 76 looks like:

if (ast.type == 'insert' && ast.returning) {

Change it to:

if (ast.type == 'insert' && ast.returning && this.client.config.client == 'postgres') {

We are using SQL Server 2017.
I made the change and it did not correct the issue.

Did it work before the Wappler update? As far as I know the above code was the only thing changed in the last update, unless you had an older version.

Yes, it worked before the update. What I did was go through a few pages on the site looking for what I needed change for the customer. I had updated Wappler on Thursday but have not used it since. I made a simple html change but Wappler uploaded all the updated core files. When I returned to the site to test it, that’s when the Retrieve Identity broke. Now, it may have been 3.5.6 that broke it, as I have not had to update this site in a couple of weeks.

We didn’t have any other changes to the database module in the last 3 months other than the above.

Is there another way to troubleshoot it besides having to revert to an earlier version and upload the Lib files?

I pulled the files from a backup of the server. Only when I replace my Server action did it work. I checked my server action and it is the same as it was last time, so I put the two files in a file compare and the one that is working (from the backup) has line 41 “returning”: “AppointmentID”. The new file does not have that, even though the server action is the same.

File compare:

One on the left works, it’s the backup. One one the right does not, it’s the new file. Here is the server action, same as before the update:

The only thing I have done differently in the server connect files is I added a column to the insert step. It works correctly adding the value, there are no errors.

It is 3.5.7 that is not including the line to return the identity in the server connect file.

Are you sure that the old one has the returning and the new one not? The fix we had was adding the returning instead of removing it.