App Version Number

How are we able to get the app published version number from the system. I can get the "latest" to display, but I want the actual version number associated with that also. If I am trying to document an issue, or looking for information, "latest" is not always the best to work from since that is a moving target from release to release.

{{ retoolContext.pageTag }} = "latest"

I would like to see how I can get something that produces {{ retoolContext.pageTag.Version }} = "1.0.2" so I can actually capture the release numbers also. Is there an easy way to do this? Other then a manual process of storing data into a variable and updating it each time I publish a release, I have not been able to figure out how to get this data yet.

Ideas? Suggestions? Help.......

1 Like

Hi @jcook78,
If you are getting latest it would suggest you haven't created a release yet or not in user mode or the URL has ?_releaseVersion=latest .

Go to releases >> Create new >> Select "Create and publish" >> click create and publish.

chrome_dKqRryGFkI

Then you need to open the app in user mode:

chrome_LFCXGxi5OS

In the URL make sure you delete ?_releaseVersion=latest then hit enter.

Now in the debug console enter console.log('version: ' + retoolContext.pageTag)

You should get your version now.

That does work for a logged in user, yes. For a public app, the URL is already defined and shared. There is no way that I can see, to remove the ?_releaseVersion=latest in the URL.

Any other thoughts or avenues to pursue?

Can you share the public url?

If for some reason you need to retrieve it (or record it) while a user is accessing the public app, I don't believe there is a way to capture this unless you set a variable yourself.

You could also store the version in a table and have the app pull the version every time you or a user loaded the page.

Is this something you are interested in?

I can handle that, if that is the only way to do it. I was hoping there was a workaround that someone knew of.

Feature Request

1 Like

I think so for the moment.

You can always ask during office hours. There are always a few Retool team members and they are very helpful. I will ask if I am there tomorrow.

2 Likes

@jcook78 I just popped into office hours and we have gone as far as we can go.

There is already a feature request for this feature. @Jack_T if you find the link to this please add both of us. :grinning:

1 Like

Hi @jcook78 :wave:

You can use {{ retoolContext.pageTag }} which will automatically update as you publish new releases. View in Preview mode to see the current version. In edit mode you're always viewing latest therefore pageTag state alway evaluates to "latest"! Could you send screenshots if you're having issues with the actual public url as an end user? See edit and preview below:


I am able to get this to work if an end user is logged into the platform. If it is through the public url, then the version does not even show up.


@jcook78, here's an almost fully automated approach.

Create a variable to hold the latest version latestAppVersion.

Add a version table app_versions:

Create a simple query to pull the latest version (or a list of them) getAppVersions:

select * from app_versions
order by updated_at desc

Note: order by updated_at desc is important in this case. You could also just pull the latest with LIMIT 1.

Create an upsert query upsertAppVersion:

INSERT INTO app_versions (app_version, app_id)
VALUES ({{ appVersion }}, {{ appId }})
ON CONFLICT (app_version, app_id) DO NOTHING;

Add a JS query checkAndSetAppVersion and set it to trigger on page load:

console.log("checkAndSetAppVersion started");

const appId = retoolContext.appUuid;
let appVersion = retoolContext.pageTag;

// Step 1: Trigger `getAppVersions` and capture latest version
const result = await getAppVersions.trigger();
console.log("Raw result from getAppVersions:", result);

// Step 2: Extract the latest version from returned data
const latestVersion = result?.app_version?.[0] || null;
console.log("Latest version from DB:", latestVersion);

// Step 3: Set `latestAppVersion`
latestAppVersion.setValue(latestVersion);
console.log("latestAppVersion set to:", latestVersion);

// Step 4: Determine which version to upsert
if (!appVersion || appVersion === "latest") {
  console.log("Using latest version from DB as appVersion");
  appVersion = latestVersion;
}

console.log("Final appVersion to upsert:", appVersion);

// Step 5: If appVersion is valid, trigger the upsert query
if (appVersion) {
  console.log("Triggering upsertAppVersion...");
  await upsertAppVersion.trigger({
    additionalScope: { appVersion, appId },
    onSuccess: async function() {
      console.log("Upsert successful.");

      // Step 6: Set `latestAppVersion` to the upserted value
      latestAppVersion.setValue(appVersion);
      console.log("latestAppVersion updated after upsert:", appVersion);

      // Step 7: Refresh `getAppVersions`
      console.log("Refreshing getAppVersions...");
      await getAppVersions.trigger();
    },
    onFailure: function(error) {
      console.error("Upsert failed:", error);
    }
  });
} else {
  console.warn("No valid app version found. Skipping upsert.");
}

Once set up you just need to have open the user mode open while or after developing without ?_releaseVersion=latest in the URL.

That should be it. Now whenever you create a new release, go over to the user mode and hit refresh on the page. This will upsert the new version if needed. In public mode you will see the most recent version recorded in the table.

Hopefully this helps!

2 Likes