Greetings,
At the moment, I'm writing a script, which restricts which use can be selected as an Actor. My idea is to get all users from the specified group and delete the result which came when a users type something in the input field. Now, I have the problem that I am not able to get the keypress event (or change) from the select field. I wrote sth. like that.
Rather than trying to delete things as users write them, why not just run a check on the selection? i.e. user selects an actor you don't want to be selected, the script flags this selection and makes them pick a new one.
Hello Ken,
by now I solved the problem on myself. The main problem was that the script was in an IFrame, where you have to wait for it to load to access it. The thing is that Jira is written in React, and after each input the users reappear. Since this was a client task, I'm not allowed to leak all the code, but I'll explain the approximate steps for those who are interested 1. The script must not work until the IFrame is loaded (code is below) 2. Get the automation ID (the input fields are all unique) 3. Go through the list after each input and compare the users with each other (here you have to save the fields to show them again at the next input) 4. Delete the "cards". For the user list, you can create normal API calls and create a list. I ended up with 3 scripts. One that searched with global groups, one that worked within projects (and you could also search for the project roles) and one that also worked in the global administration and also filtered with for users that are in multiple projects or all. Finally, in the scripts the difference was that the users were obtained differently (the smallest has with documentation 160 lines, the third 320). Important is, that you just have to reload the IFrame when you click on another Automation (just use:
document.getElementById('iFrameResizer0').src += '';
).
To get the Input, you need this:(
$("#iFrameResizer0").contents().find(`#react-select-${automationID}-input`).val();
).
You should generally use "$("#iFrameResizer0").contents().find()" to get any other element of the IFrame.
// Listens for user input and checks the selectable users each time the user presses a key
function actorRestriction() {
$(document).ready(function () {
$("#iFrameResizer0").on("load", function () {
setTimeout(() => {
const Actor = $("#iFrameResizer0").contents().find("#actor");
if (Actor.length) {
console.log("Success. Actor script is now running");
Actor.on("keydown", async function () {
await elementWaiter($("#iFrameResizer0").contents().find(`#react- select-${automationID}-option-0`));
});
} else {
console.log("failed to start Actor script");
};
}, 1000);
});
});
};
I hope I could help you (when you have other questions, just ask) and I'm really sorry, that didn't read the comment.
Kind regards,
Gauthier
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.