Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,633
Community Members
 
Community Events
185
Community Groups

Set form value in behavior initialiser script but Fields script unable to get that value

Edited

I have a behaviour that uses an Initialiser script to set a custom user picker field to the currently logged in user and this works without issue.

import com.atlassian.jira.component.ComponentAccessor;

if (getActionName() != "Create") {
return;
}

def userField = getFieldByName("Target User");
def currentUserName = ComponentAccessor.jiraAuthenticationContext.loggedInUser.name;
userField.setFormValue(currentUserName);

 But I also have a server-side script on that same "Target User" field in the same behaviour that checks the value of the "Target User" field and if that user is the same as the currently logged in user a "Requester Agreement" custom checkbox field would be visible and required. If they are not the same user then the "Requester Agreement" custom checkbox field would be hidden and not required.

The idea is that initial, when the form is initialized the "Target User" is set to the same as the currently logged in user and because of this the "Requester Agreement" field is visible and required. But if the user changes the "Target User" field to another user then the "Requester Agreement" field is hidden and not required.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;

if (getActionName() != "Create") {
return;
}

def currentUserName = ComponentAccessor.jiraAuthenticationContext.loggedInUser.name;
def targetUserField = getFieldById(getFieldChanged());
def requesterAgreementField = getFieldByName("Requester Agreement");

log.info("Target User: $targetUserField");

if (currentUserName == targetUserField.getValue())
{
requesterAgreementField.setHidden(false);
requesterAgreementField.setRequired(true);
}
else
{
requesterAgreementField.setHidden(true);
requesterAgreementField.setRequired(false);
requesterAgreementField.setFormValue(null);
}

But for some reason the "Target User" field has a null or empty string value. The logs show: 

Target User: Form field ID: customfield_10700, value:

I can't figure out why this is... I see the logging lines in script being run at least 2 times when the form loads but rarely the form will load 4 times and on the 4th time the "Target User" field will actually show the expected value.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events