Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner script doesn't run

ganna_kyselevych December 20, 2023 edited

I need to make a field SEO_Type of asset visible when the Label_BM filed is BM_SEO and invisible when the label is any other during the ticket creation. 


I use the following script and it makes a field SEO_Type of asset invisible in any case:

const labelsBMField = getFieldById("customfield_12525");
const seoTypeOfAssetField = getFieldById("customfield_12702");

seoTypeOfAssetField.setVisible(true);

const labelsBMValue = labelsBMField.getValue()?.name;
if (labelsBMValue == 'BM_SEO') {
seoTypeOfAssetField.setVisible(true);
} else {
seoTypeOfAssetField.setVisible(false);
}

What is wrong?

 

image.png

1 answer

0 votes
Mohammed Aamer Khan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2023

@ganna_kyselevych
You have to store value as string to compare. Let me know if it works

const labelsBMValue = labelsBMField.getValue()?.name.toString(); //Converts value to string

If above doesnt work Try below code
const labelsBMValue = labelsBMField.getValue().toString(); //Converts value to string

ganna_kyselevych December 21, 2023

Unfortunately, nothing changed 😞

First option:

const labelsBMField = getFieldById("customfield_12525");
const seoTypeOfAssetField = getFieldById("customfield_12702");

seoTypeOfAssetField.setVisible(false);

function updateVisibility() {
const labelsBMValue = labelsBMField.getValue()?.name.toString();

if (labelsBMValue === 'BM_SEO') {
seoTypeOfAssetField.setVisible(true);
} else {
seoTypeOfAssetField.setVisible(false);
}
}

labelsBMField.onChange((fieldId, newValue, oldValue) => {
updateVisibility();
});

updateVisibility();

Second option:

const labelsBMField = getFieldById("customfield_12525");
const seoTypeOfAssetField = getFieldById("customfield_12702");

seoTypeOfAssetField.setVisible(false);

function updateVisibility() {
const labelsBMValue = labelsBMField.getValue().toString();

if (labelsBMValue === 'BM_SEO') {
seoTypeOfAssetField.setVisible(true);
} else {
seoTypeOfAssetField.setVisible(false);
}
}

labelsBMField.onChange((fieldId, newValue, oldValue) => {
updateVisibility();
});

updateVisibility();

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
atlassian, jira service management, jsm webinar, ai in jsm, opsgenie integration, incident management, virtual agent, atlassian intelligence, ai-powered service desk, it operations, atlassian learning, service management webinar, team '25 recap

What’s new in Jira Service Management 🤔

Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.

Register here ⬇️
AUG Leaders

Atlassian Community Events