Need examples on how to use BeanShell scripts

Issue #27 new
Former user created an issue

Hello.

You gave no examples of using BeanShell scripts.

We hope that this opportunity can help us to archieve the goal: after changing field1(type:select) is ServiceDesk Problem ticket we need to send this selected value to corresponding fields field2 (select) for all Bugs in Jira Software which are linked to this Problem and has "lower" value in their select field.

We can't do such fields comparision by JQL because fields of type 'select' can't be compared directly.

Comments (4)

  1. Yury Oboz repo owner

    Hi!

    beanshell code like Java:

    import com.atlassian.jira.component.ComponentAccessor;
    import com.atlassian.jira.bc.issue.search.SearchService;
    import com.atlassian.jira.user.ApplicationUser;
    import com.atlassian.jira.web.bean.PagerFilter;
    import com.atlassian.jira.util.thread.JiraThreadLocalUtil;
    import org.apache.log4j.Logger;
    import com.atlassian.jira.issue.Issue;
    import java.util.Collection;
    import com.atlassian.jira.issue.search.SearchResults;
    import com.atlassian.jira.user.UserUtils;
    
    JiraThreadLocalUtil jiraThreadLocalUtil = ComponentAccessor.getComponentOfType(JiraThreadLocalUtil.class);
    ApplicationUser user = UserUtils.getUser("admin");
    SearchService searchService = ComponentAccessor.getComponentOfType(SearchService.class);
    SearchService.ParseResult parseResult = searchService.parseQuery(user, "project = CORE and description ~ " + issue.getKey());
    jiraThreadLocalUtil.preCall();
    Collection out = searchService.search(user, parseResult.getQuery(), PagerFilter.newPageAlignedFilter(0, 300)).getResults();
    jiraThreadLocalUtil.postCall(Logger.getLogger("beanshell"));
    return out;
    

    I add support for groovy in nearest future

  2. Valentine V

    Thank you. Your code sample helped me a lot.

    But now I’m stuck at next point: your app is executing my BeanShell code every time the issue changed 😞 .
    I expected that it’ll run only when configured source field(s) is(are) changed.
    I wanted to eliminate this useless runs by checking the issue changeLog for my source field prior to main code to skip the rest, but I can't.
    I’m newbie in Java and I know how to do this with help of Groovy and “event” object with Script Runner.

    But how can I get changeLog to parse it for updated fields with BeanShell?

    p.s. Can you reveal a plans of implementing groovy scripting in your app?

    p.p.s. May be I should create a feature request too? Something like “Plugin should skip doing anything if IssueUpdated event have no signs of source fields changes“.

  3. Yury Oboz repo owner

    Hi!

    “event“ object do not provided in scope for beanShell. But I injected this object to groovy script.

    Can you reveal a plans of implementing groovy scripting in your app?

    I already test new version with groovy module and plan to post the release next week.

    May be I should create a feature request too? Something like “Plugin should skip doing anything if IssueUpdated event have no signs of source fields changes“.

    I will think about this.

    p.s. If you want to join testing try add-on from attachment

  4. Log in to comment