YouTrack App Settings missing id for referenced entities
Dear YouTrack Team,
we are trying to build a YouTrack App that is using entities in the App Settings, in this case a referenced Project:
"properties": {
"referenceProject": {
"title": "Reference Project",
"type": "object",
"description": "Reference Project",
"x-entity": "Project"
},
...
}
To fetch the settings inside of the app we are using a backend endpoint like stated in the documentation:
exports.httpHandler = {
endpoints: [
{
method: 'GET',
path: 'settings',
handle: function handle(ctx) {
const settings = ctx.settings;
ctx.response.json(settings);
}
}
]
};
All other setting fields, like simple strings for this app are working fine. But when I try to read this entity in the app with the `ctx.settings` field, I only receive the following object inside the ctx.settings. What I am missing is the specific project id or name of the entity.
{
...
"referenceProject": {
"becomesRemoved": false,
"isNew": false,
"$$type": "Project"
},
...
}
Do you have any idea why there is no id or name in the fetched settings? Is it a permission problem, or something like that? Many thanks for any suggestions.
Best regards
Malte Bruweleit | MSP AG
Please sign in to leave a comment.
Hi Malte Bruweleit!
Fetching app settings inside the app doesn't require using endpoints, so calling
ctx.settings.referenceProject
should be enough to obtain the project. Can you please try this approach and see if it makes any difference?In case I'm misinterpreting the issue and you already use
ctx.settings.referenceProject
(or if using HTTP handlers is required by some other app), can you please share the app with me for further review? Feel free to remove all the sensitive data from there. You can also share it in a ticket with our support team: https://jb.gg/ytsup.Hi Julia Bernikova ,
thanks for your answer, appreciate that :)
That is quite easy to showcase, I would refer to the App that gets bootstrapped using the CLI via
npm create @jetbrains/youtrack-app
There it generates following React Component and it uses a backend call to a HTTP handler which was the only location I found in which you can retrieve the ctx, containing the settings:
HTTP Handler
How would you read the
ctx.settings.referenceProject
directly in the React Component without using a HTTP handler? I think I am just lacking an example how to obtain the ctx in the React Component.Thank you very much and best regards
Malte Bruweleit | MSP AG
Hi Malte Bruweleit,
Thanks for the reply! I completely overlooked the fact that you might be using a widget, not just scripts. Let me check with the developers how best to obtain the project setting of the app with all its properties. I'll update the thread once I have an answer!
In the meantime, just as a temporary solution, you can make the handler return the exact project name with
ctx.response.json(ctx.settings.referenceProject.name);
.Hi Julia Bernikova
thank you very much for your effort.
It would be really great if you could check with the devs if there is some kind of misbehavior with the app settings and the retrieval of the settings of referenced entities, because that is what I tried:
In my scenario the
ctx.settings.referenceProject.name
is undefined, also thectx.settings.referenceProject.id
although there is definitely a project referenced in the app settings. In the fieldctx.settings.referenceProject
there is only available:So I thought it might be some kind of permission issue regarding the project and the app.
Looking forward to your findings and best regards
Malte Bruweleit | MSP AG
Hi Malte Bruweleit,
Thank you for your patience!
I've discussed the issue with the dev team, and it seems there's no way to easily return objects like the project setting in HTTP handlers. We registered this issue in our tracker: https://youtrack.jetbrains.com/issue/JT-89389/Consider-improving-toString-for-workflow-API-objects.
For now, we'd recommend building a new object based on the properties you need:
You mentioned that those properties are undefined on your side - can you please make sure the project is indeed selected in the settings (global/project-level depending on the app implementation)?