SR Behavior with code: Conditionally show/hide custom fields based on a value selected in Jira Cloud
***Code at the end*** Click on the following playlists to learn more about - ScriptRunner for Jira - https://www.youtube.com/playlist?list=PL2nigeawcQ2Wh8O0wKZdvPyfcEPhOOds5 Jira Service Management PlayList - https://www.youtube.com/playlist?list=PL2nigeawcQ2XjE0_uXbZpAIII99UItyQ5 Jira Software PlayList - https://www.youtube.com/playlist?list=PL2nigeawcQ2XMsTwRgong1Mj3pRXTxLot Confluence PlayList - https://www.youtube.com/playlist?list=PL2nigeawcQ2WnhqCfAO3PvQ5MxTIxYbHT Automation Rules PlayList - https://www.youtube.com/playlist?list=PL2nigeawcQ2UEBHTW62HKjarGkFPlKx4P Insight Asset Management PlayList - https://www.youtube.com/playlist?list=PL2nigeawcQ2XlsBOFPoq7DmEp0WHs1s-q Miscellaneous Items PlayList - https://www.youtube.com/playlist?list=PL2nigeawcQ2VE0dp-ThaVrLcap7OE10jc ------------------------------------------------------------------------------- ***Display the Custom Field based on the value selection:*** // Insert the Jira UI modifications API script for the behaviour. //storycategoryField is the field that takes the value and triggers what custom field to be displayed const storycategoryField = getFieldById("customfield_xxxxx"); //discoveryField is one of the field values displayed in the story category field const discoveryField = getFieldById("customfield_xxxxx"); //Initially, do not display the 'Discovery' field on the screengetFieldById("customfield_xxxxx").setVisible(false) //check the storycategory field value logger.info('Value : '+storycategoryField.getValue().name); //If the story category field value is 'Discovery', display the Discovery custom field if(storycategoryField.getValue().name == 'Discovery') { discoveryField.setVisible(true); logger.info('true'); }else{ discoveryField.setVisible(false); logger.info('false'); } ------------------------------------------------------------------------------------ ***Custom field with pre set values /Template - this code is for custom field type paragraph wiki style field renderer. For default text renderer, this code will not work*** // Insert the Jira UI modifications API script for the behaviour. // Discovery is a custom field const discoveryValue = getFieldById("customfield_xxxxx").getValue(); const discoveryValueContent = discoveryValue.content.toString(); logger.info(discoveryValueContent) if (!discoveryValueContent) { getFieldById("customfield_xxxxx").setValue({ "version": 1, "type": "doc", "content": [ { "type": "paragraph", "content": [ { "type": "text", "text": "Discovery ", "marks": [ { "type": "strong" } ] }, { "type": "text", "text": "A discovery is a preliminary phase in the UX-design process that involves researching the problem space, framing the problem(s) to be solved, and gathering enough evidence and initial direction on what to do next. Discoveries do not involve testing hypotheses or solutions." } ] }, { "type": "paragraph", "content": [ { "type": "text", "text": "Prerequisite ", "marks": [ { "type": "strong" } ] }, { "type": "text", "text": "Does a PRD exist? Reference the PRD for clarification on problem and goals." } ] }, { "type": "paragraph", "content": [ { "type": "text", "text": "Problem ", "marks": [ { "type": "strong" } ] }, { "type": "text", "text": "(What’s wrong? Is this a business, user or technical problem?)" } ] } ] }) } ------------------------------------------
Download
0 formatsNo download links available.