Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Submit form to custom rest (POST)

Hey,

I'm trying to submit an HTML form in JIRA dialog.

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript

import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

showDialog(){ MultivaluedMap queryParams ->

    // get a reference to the current page...     def issuekey = queryParams.getFirst("issuekey")


    def dialog =
        """<section role="dialog" id="sr-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" aria-hidden="true" data-aui-remove-on-hide="true">
            <header class="aui-dialog2-header">
                <h2 class="aui-dialog2-header-main">Send comment</h2>
                <a class="aui-dialog2-header-close">
                    <span class="aui-icon aui-icon-small aui-iconfont-close-dialog">Close</span>
                </a>
            </header>
            <div class="aui-dialog2-content">
                <p>
                <form action="http://localhost:8080/rest/scriptrunner/latest/custom/sendcomment" method="post" id="usrform" class="aui" enctype='application/json'>                 <fieldset>
                <textarea class="textarea" name="comment" id="textarea-id" placeholder="Your comment here..."></textarea>
                </fieldset>
                <input id='issuekey' type="hidden" name="issuekey" value='"""+issuekey+"""'>
                <div class="buttons">
                <input class="button submit" type="submit" value="Submit" id="comment-save-button">
                </div>
                </form>
                </p>
            </div>
            <footer class="aui-dialog2-footer">
                <div class="aui-dialog2-footer-actions">
                    <button id="dialog-close-button" class="aui-button aui-button-link">Close</button>
                </div>
                <div class="aui-dialog2-footer-hint"></div>
            </footer>
        </section>
        """

    Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}

 

The problem is that I get "XSRF check failed" error.

I even tried to just print a log from the custom rest but I it does not print to the logs.

I get this is the log error:

2018-04-04 11:58:54,477 http-nio-8080-exec-4 WARN admin 718x3452x1 jr3nl4 0:0:0:0:0:0:0:1 /rest/scriptrunner/latest/custom/sendcomment [c.a.p.r.c.security.jersey.XsrfResourceFilter] XSRF checks failed for request: http://localhost:8080/rest/scriptrunner/latest/custom/sendcomment , origin: http://localhost:8080 , referrer: http://localhost:8080/projects/STAR/issues/STAR-1

I saw that the solution it submit the form with JQuery but It's not recommended to add <script> tag to inline groovy code

add this to the post header- "X-Atlassian-Token", "nocheck"

Is anybody know a way to add it to the HTML code?

Thanks

1 answer

0 votes

Hi! 

 

Have you implemented it? https://stackoverflow.com/questions/9516865/how-to-set-a-header-field-on-post-a-form

But you can do it as ajax function 

like this 

$.ajax({    url: 'foo/bar',    headers: { 'X-Atlassian-Token': 'nocheck' }
});

 

Cheers,

Gonchik Tsymzhitov 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

62 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you