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.referenceProjectshould 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-appThere 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.referenceProjectdirectly 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.nameis undefined, also thectx.settings.referenceProject.idalthough there is definitely a project referenced in the app settings. In the fieldctx.settings.referenceProjectthere 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)?
Hi Julia Bernikova ,
thank you very much for your answer and your effort. I tried it the way you described and with that in place I am able to read certain specifics from the referenced project. But unfortunately I cannot retrieve the technical id, in my case it I need something like '0-448' which is needed to create issues for that project.
I tried to guess some fields, as it is not really transparent which fields can be read.
This returns the shortName of the project, which cannot be used to create issues for that project.
That property returns unfortunately nothing, which I suspected could return the technical id.
So our workaround now is to store the technical id of the project directly as a string in the App Settings. Not optimal, but working for now.
instead of
Thanks again for your effort on this topic.
Best regards
Malte Bruweleit | MSP AG
Hi Malte,
Thanks for the update, I'm glad to hear you found an alternative solution!
The project ID is indeed not exposed to the workflow API at the moment, I registered an issue about that: https://youtrack.jetbrains.com/issue/JT-89865. One other way to obtain it would be via the REST API if that works in your scenario. Let me know if you'd like to explore this approach and have any questions!
Hi Julia,
thank you for your answer.
Yes we now were able to set the project as entity reference in the App Settings. In the app reading the “key” of the referenced project, which is the short name and retrieve via Rest API the technical id of the corresponding project and using it. One more request to the Rest API won't hurt I guess ;) till the technical id itself can be exposed.
Thanks for your great support!
Best regards
Malte Bruweleit | MSP AG
Hi Malte,
Thank you for your kind words and full cooperation! And don't hesitate to reach out if any questions occur.