Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

atlassian-connect-express 9: add your own settings to the database

Hello!

In this article we will see how to add your own settings to the database.

This article is based on this one.

You can find the source code for the article here.

You can find a video for this article here.

Let’s say your application depends on some settings which are set by your application. Either you save it automatically or a user sets the settings in some of the pages of your application.

First of all, always consider to store the settings for your app in the Jira, Confluence or Bitbucket itself. On the date of writing this article it is not possible to store settings in Bitbucket itself. That is why we need to store settings in our database.

There are a couple of ways to do it. I will show you the simplest one.

When our app is installed the AddonSettings table is created:

Screenshot 2021-05-24 at 11.14.11.png

This table contains 4 fields: id, clientKey, key and val. By default atlassian-connect-express saves necessary to the framework data in rows where the key equals to clientInfo.

That is why to add your own settings you can add rows with your own key. Let’s say we call our key “appSettings”.

The val columns should be always a json.

Now let’s add our own row on app installation. We should change the code in backend/app.js:

addon.on('host_settings_saved', function(clientKey, data) {
    console.log('host_settings_saved')
    console.log(clientKey)
    console.log(data)
});

to this one:

addon.on('host_settings_saved', function(clientKey, data) {
    console.log('host_settings_saved')
    addon.settings.set('appSettings', {settings1: "settings1 value"}, clientKey)
        .then(() => {
            addon.settings.get('appSettings', clientKey)
                .then((settings) => {
                    console.log(settings)
                })
        })
});

In this code we first create a new row with the appSettings key and then read it and log the result into console.

Now we need to delete the row if we uninstall our app. That is why let’s make the uninstalled endpoint look like this:

    app.post('/uninstalled', addon.authenticate(), function (req, res) {
        addon.settings.del('appSettings', req.context.clientKey)
            .then(() => res.send(200))
    })

We delete the row and then return the success status code.

Now let’s try to install our app again.

Here is the AddonSettings table:

Screenshot 2021-05-24 at 12.33.05.png

We can see that the row with the appSettings key was added.

Now let’s examine the logs and see if we can read the data from the row:

{ settings1: 'settings1 value' }

Yes, we are able to read the values.

Now let’s uninstall and see if the row was deleted:

Screenshot 2021-05-24 at 12.35.11.png

Yes, the row was deleted.

Everything works as expected. That is all for the article.

See you in the next article.

1 comment

Mohammed Amine Community Leader May 30, 2021

Great article @Alexey Matveev _Appfire_ you are really helping the community with this. Keep up the good work. 

Are you offering (or willing to offer) a training on Atlassian App dev? 

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Jira issue check and more advanced commit verifications for Bitbucket DC

Pre-receive hooks that verify the Git commit message, the modified files, and implement similar code change controls used to be requirements of large enterprises working in regulated industries only....

50 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you