Set Customfield with Javascript

Hi All, 

I've been tasked to set a customfield with Javascript. 

Back story is that i want to query an API via javascript and then get the return values to set the customfields in the create screen so it "Auto-populates" certain customfield. 

Im currently having difficulties, just setting the customfield field with free text.

The current code i have is

<script type="text/javascript">
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
setDefaultValues();
});
setDefaultValues();

function setDefaultValues(){
setFieldValue();
}

function setFieldValue(){

$("#customfield_13600").val('Test');

 

});
</script>

 But it doesn't seem to set the customfield to "Test".

Any help is much appreciated.

Thanks, 

Pon

2 answers

1 accepted

 

Hi @Pon Yuntawai

Could you try this , maybe it can help you.

<script type="text/javascript">

AJS.$("##customfield_13600").val("default value");

summuryField.hide();

</script>

Hi @zezeto[Nadir.Meziani],

Thanks for your help!

Unfortunately this did not work :(

Hi @Pon Yuntawai

Sorry , 

<script type="text/javascript">

AJS.$("#customfield_13600").val("default value");

</script>

could you share here screenshots?

Hi @zezeto[Nadir.Meziani],

Ahh its working with:

<script type="text/javascript">

AJS.$("#customfield_13600").val("default value");

</script>

Thank you so much for your help!

i really appreciate it.

Cheers, 

Pon

hey @zezeto[Nadir.Meziani],

 

By any chance do you also know how to get custom field values via ajax? 

so like for example if i put in 123 value into a field, can i grab that value by any chance?

Many thanks for your help 

Actually i got it :)

 

var custNo = document.getElementById("customfield_10000").value;

hi @Pon Yuntawai

Or like this

<script type="text/javascript">

AJS.$("#customfield_13600").val();

</script>

, without put anythings in val () fuunction.

1 votes
Tayyab Bashir Community Champion Oct 16, 2017

Hi, 

$("#customfield_13600").val('Test');

The above won't work because the free text value is in form of an input and it's panel is inactive in idle mode (unless you double click and a text box appears) 
so the id, customfield_13600 does't exist yet. 

 

Use the following: 

AJS.$("#customfield_13600-val").text("Test Test Test")

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,789 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot