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

Scriptrunner custom template issue for picklist

Sreenivas Narala May 11, 2022

Hi Folks,

I have crated a picklist custom filed with Groovy script by using below custom template, am able to list out all the required values in picklist but not able to save/hold the selected specific value from the list if user perform any operations like page refresh or filling other values picklist displaying default/first value from the list,

Please find the below custom template lnline code 

<p>
<select id="Planview Project Name">
$value
</select>
</p>  

May i know how we can save/hold the specific value from the picklist. Thankyou in advance.

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 14, 2022

Hi @Sreenivas Narala

Could you provide a little more information, i.e. what have you used to configure your picklist? Is it Scripted Fields?

From the code that you have shared, it appears to be more of a javascript.

Could you please share the complete code you are currently using and a screenshot of your configuration so it can be reviewed?

Thank you and Kind regards,

Ram

Sreenivas Narala May 15, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Yes, I have configured Scripted Field with Groovy.

Based on my requirement want to display return values as a picklist/dropdown field and want to save selected value from the list at dashboard/issue creation.

i don't have any issue with source code and facing issue with custom template(picklist/Dropdown).

Below code for Advanced custom template return value(picklist/Dropdown).

<form>
<select id="Planview ProjectName">
<option selected disabled>--Select ProjectName--</option>
$value
</select>
<span class="overlay-icon throbber"></span>
<div class="save-options" tabindex="1"><button type="submit" class="aui-button submit" accesskey="s" title="Press Alt+s to submit this form" resolved=""><span class="aui-icon aui-icon-small aui-iconfont-success">Save</span></button><button type="cancel" class="aui-button cancel" accesskey="`" title="Press Alt+` to cancel" resolved=""><span class="aui-icon aui-icon-small aui-iconfont-close-dialog">Cancel</span></button></div>
</form>

 

Below is the source code to fetch the data by using API and list out json data by using for loop :-

import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import java.net.HttpURLConnection;
import net.sf.json.groovy.JsonSlurper
import net.sf.json.JSON;
import groovy.json.JsonBuilder
import java.util.TreeSet;

// Source code from below REST API

def get = "https://abc-planview-service.eu-gb.mybluemix.net/api/v2/projects?token=XXXXXXX".toURL().text
def json = new JsonSlurper().parseText(get)
def Name = json."name"
def result = ""
def sort = new TreeSet();

for (key_value in json) {
def Status_Value = key_value."status"
def BU_Value = key_value."bu"
def ProjectCategory_Value = key_value."projectCategory"

if (!((Status_Value == 'WBS20$CNCL') || (Status_Value == 'WBS20$CLOS') || (ProjectCategory_Value == "MVP Agile") || (BU_Value == "Property & Facilities Solutions")))
{
sort.add(key_value)
}
}

for (key_value in sort) {
result = result + "<option>"+key_value.name
}

return result

 

Please refer attached screenshots for reference and let me know if anything is neededScriptField_1.pngScriptField_2.pngCurrentOutput.pngExpectedOutput.JPG

TAGS
AUG Leaders

Atlassian Community Events