How to use javascript to set security level

Hi,

I am trying to set the security level by using the name of the level. However, I can only find this info

AJS.$("#security").val("10500")

where 10500 is the ID of the level. I don't want this, I want to set the value by using the name of the level (e.g. Inhouse Level). I tried

AJS.$("#security").val(" Inhouse Level ")

But it doesn't work. Please help.

Thanks,

1 answer

1 accepted

0 vote

Well, id is what should go in the field and so you will have to set it. Maybe you can iterate on the options and find the option value using text before you set it in the security field.

Having said that, id is the safe bet because it will remain the same even if you change the security level name later. Id will change only if you delete the security level and recreate it.

Sorry, I should explain this clearer. What I am doing is I have another script to identify current user's group and based on that set the level to be exactly as the group (e.g. FFX group will have FFX level)

How can I iterate through options in Security field using AJS please?

I tried something like this

<script type="text/javascript">

for (i = 0; i < AJS.$("#security").length; i++) {

if (AJS.$("#security")[i].text = "FFX") {

alert(AJS.$("#security")[i].value);

}

}

</script>

But it seems it still output the current selected value instead of the real value of FFX level.

Shouldn't you use == during String compare? You can also iterate using jquery:

AJS.$("#security > option").each(function(){
// Do the rest

});

Thanks for the helps. Have got this working

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 4 hours ago in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

16 views 0 3
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you