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

Create html element in execution time

Daniel Luevano August 26, 2015

I want to replicate the flag Bugzilla behaviour:

Flag fields (list item with: '+','-','?','N/A') are created based on the database information, flags are only available on Edit form, here is how they work:

'Flags' table contains two columns 'flag_Type' and 'bug_id'

Then if editing bug (id=111) is not on the 'Flags' table, just one CR Flag field is shown in blank, otherwise the CR(n) is shown with the username who approved the flag PLUS one in blank CR flag field.

Attached some example images.

FlagTable.png

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Kristian Walker _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.
January 5, 2016

Hi Daniel,

Can you please advise how you would receive this output from Bugzilla.

I have enclosed a sample script below which shows how you can create HTML table similar to above using Groovy code which is run in a scripted field so that it gets re ran every time the issue is refreshed.  The script could be modified so that rows of the table could be auto populated from an xml file or even the database.

import groovy.xml.MarkupBuilder
  
StringWriter writer = new StringWriter()
def build = new MarkupBuilder(writer)
build.html{
 head{
    style(type:"text/css", '''
    .header {
        margin: 30px;
        padding: 10px;
        background-color: #d9d9d9
    }
      .row {
        margin: 30px;
        padding: 10px;
        background-color:  #b3f0ff
    }
    ''')
  }
  body{
    table{
      // Heading Row
      tr{
        th('class':'header',"id")
        th('class':'header',"type_id")
        th('class':'header',"status")
        th('class':'header',"bug_id")
        th('class':'header',"attach_id")
        th('class':'header',"creation_date")
        th('class':'header',"modification_date")
        th('class':'header',"setter_id")
          {
        // Data Row
        tr{
         td('class':'row',"12232")
         td('class':'row',"9")
         td('class':'row',"+")
         td('class':'row',"34234")
         td('class':'row',"NULL")
         td('class':'row',"2015-05-01-12:00GMT")
         td('class':'row',"2015-05-01-12:30GMT")
         td('class':'row',"342")
          }
        // Data Row
        tr{
         td('class':'row',"43521")
         td('class':'row',"10")
         td('class':'row',"N")
         td('class':'row',"21304")
         td('class':'row',"NULL")
         td('class':'row',"2015-05-01-13:00GMT")
         td('class':'row',"2015-05-01-13:30GMT")
         td('class':'row',"123")
          }
        // Data Row
        tr{
         td('class':'row',"30053")
         td('class':'row',"1")
         td('class':'row',"-")
         td('class':'row',"85942")
         td('class':'row',"NULL")
         td('class':'row',"2015-05-01-11:00GMT")
         td('class':'row',"2015-05-01-11:30GMT")
         td('class':'row',"934")
          }      
        }
      }
    }
  }
}
return writer

I hope this helps.

Thanks

Kristian

Daniel Luevano January 5, 2016

Hi Kristian, Thanks for your answer, nevertheless the table above is to show how Bugzilla determines if creates a new html element or not. What I need to do is to create a listbox with the options ('+','-','?','N/A') based on a database request. For example: If query below is >= to 1 then create a listbox element and show the information of the record found and create a new element without information. 'select count(bug_id) from flags where bug_id=12345' Let consider this scenario, the query above is 1, then I got all the record information, in page I will see the next elements: CR [list box with value] [user_mail] CR in blank (this HTML element should be created only because there is a record) I need to save the information of this new CR flag in the 'Flags' table. Is there a routine in groovy or SIL language than I can modify information from database? Thanks in advance.

Kristian Walker _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.
January 5, 2016

Hi Daniel, The script runner documentation contains information on how to query a database at https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/connecting-to-databases.html#_querying_the_current_jira_database and this could be used to update records in the database if needed. However please be advised that modifying the database directly from a script is not considered a best practice as this may case the cause data inconsistency issues. I hope this helps Kristian

TAGS
AUG Leaders

Atlassian Community Events