Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

Own Post-AddResult code to trigger attachment upload

Hi there!

I want to trigger an automatic upload of log files as attachments to the test result once the result is added (via API to TestRail and maybe also to the DefectsTracker).

But the Change_ID is only generated at the submit (=pressing AddResult in the Add Result Dialog).

That results in a POST: In the response I find among other things the change_id, which can be hopefully used to attach the log files.

So my question is how to hook into the submit so I can add my own post-submit action?


Hi @semate,

Thanks for the post! You may be able to use a UI script for processing data after submitting a result, either by adding a listener or implementing a button, as outlined in our documentation. You can read about UI Scripts on our website here, and also find an example for implementing a button to trigger an external script here.

Please keep in mind we wouldn’t be able to directly troubleshoot or help develop this kind of custom script. That said, you may be able to find similar use cases and example scripts on our forums.



Thanks for your response, Jon! Unfortunatelly the example on the web page doesn’t help me much in this case.

My latest attempt was to manually trigger the submit request:
<button type=“submit” id=“addResultSubmit” style="" class=“button …” onclick=“ret = $(’#AddResultForm’).submit(); console.log(ret);”>Add Result

Where I ended up on a SendErrorReport form. What was sent was:
[HTTP/1.1 400 Bad Request 14ms]

This now compared to the message of the original, none modified button:
with the form data:
comment: some+comment+again
attachments: 2677

The bold values are not included in the submit I triggered manually and I’m not sure how to get them. Dispite of the fact that it’s a complete different message.

Maybe I’m lacking some deeper Javascript&PHP knowledge and the answer is real simple. Anyway it would make working with Testrail much more efficient if we would not have to select the same attachments over and over again for every test result.


Hi Markus,

If you are using the same attachment(s) repeatedly within a project, you can simply use Markdown formatting to link an attachment to any test result. This would not require any UI Scripts, as you can simply use Markdown formatting to include a link to any attachment within the project. Once the attachment is uploaded for the first time, you would not need to repeatedly add it to your test cases or results.

Please keep in mind that if you are using the same attachment in multiple projects, you should upload it to your test cases or results on a per project basis, as attachments retain project-level permissions.

Alternatively, you could also use Markdown formatting to link to any attachment stored on a shared server, as linking to attachments within test cases would work the same, regardless of the server hosting the actual file.

Hope this helps,