Delete Scriptrunner custom fragment causing errors

In this article i will explain how you can remove a ScriptRunner fragment if you added it and its causing errors. 


For my case , I added a fragment to show data on header like below






Later on , I updated the html and forgot to close the tag and the result were when ever i was loading any page , was getting this error and no one able to access Jira




Here are the steps which you can follow to remove any fragment through rest if its causing error.


Do a Get Call 
http://localhost:9090/rest/scriptrunner/latest/fragments 

You will see results like below


  • [
    {
    @class"com.onresolve.scriptrunner.fragments.model.CustomWebItemCommand",
    id"58269541-fa01-4c87-a695-0e720222b392",
    version14,
    ownedBynull,
    disabledfalse,
    FIELD_NOTES"showUpdateEpicDialogBox",
    canned-script"com.onresolve.scriptrunner.canned.jira.fragments.CustomWebItem",
    FIELD_KEY"mybtn",
    FIELD_WEIGHTnull,
    FIELD_SECTION"operations-top-level",
    FIELD_MENU_LABEL"Update Epic Issues",
    FIELD_MENU_LABEL_KEYnull,
    FIELD_LINK_CONDITION
    {
    script"issue.issueType?.name.toString()=="Epic" ",
    scriptPathnull,
    parameters: { }
    },
    FIELD_LINK_DESTINATION"/rest/scriptrunner/latest/custom/showUpdateEpicDialogBox?issueKey=${issue.key}",
    FIELD_STYLE_CLASSnull,
    FIELD_DO_WHAT"RUN_CODE_SHOW_DIALOG",
    name"Custom web item"
    },
    {
    @class"com.onresolve.scriptrunner.fragments.model.CustomWebItemCommand",
    id"ae3929ce-f5fa-4642-a53d-07b5778090c8",
    version7,
    ownedBynull,
    disabledfalse,
    FIELD_NOTES"epic parent",
    canned-script"com.onresolve.scriptrunner.canned.jira.fragments.CustomWebItem",
    FIELD_KEY"epicparent",
    FIELD_WEIGHTnull,
    FIELD_SECTION"operations-top-level",
    FIELD_MENU_LABEL"EpicParent",
    FIELD_MENU_LABEL_KEYnull,
    FIELD_LINK_CONDITIONnull,
    FIELD_LINK_DESTINATION"/rest/scriptrunner/latest/custom/showDialog",
    FIELD_STYLE_CLASSnull,
    FIELD_DO_WHAT"RUN_CODE_SHOW_DIALOG",
    name"Custom web item"
    },
    {
    @class"com.onresolve.scriptrunner.fragments.model.CustomWebPanelCommand",
    id"35317b57-d843-41b7-a80f-4d53514fd990",
    version41,
    ownedBynull,
    disabledfalse,
    FIELD_NOTES"SLA",
    canned-script"com.onresolve.scriptrunner.canned.jira.fragments.CustomWebPanel",
    FIELD_KEY"sla",
    FIELD_WEIGHTnull,
    FIELD_LOCATION"atl.header",
    FIELD_MENU_LABEL"sla",
    FIELD_LINK_CONDITION
    {
    script"import com.atlassian.jira.component.ComponentAccessor def loggedinuser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() if (loggedinuser) { return 1 } else { return 0 }",
    scriptPathnull,
    parameters: { }
    },
    FIELD_CLASS_NAME
    {
    script"package com.elm.scriptrunner.upwork.BMCRemedy.Fragments import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.web.bean.PagerFilter import groovy.transform.Field import org.apache.log4j.Logger @Field String execUser = "ramzan" // provide the username to authorize the request to be updated. @Field botUser=executeWithUser() @Field String S1="'Customer Request Type' ='S1 - Report Circuit Down (NEVT)' " @Field String S2="'S2 - Report Link Flapping/Intermittent, Packet Loss (NEVT)' " @Field String S3="'S3 - Network Slowness (NEVT)' " writer.write(""" <div style='background-color: darksalmon; text-align: center'> <b>S3-Open Tickets </b>: ${findIssues(S3).size()}</div> <div style='background-color: silver; text-align: center'> <b>S2-Open Tickets</b>: ${findIssues(S2).size()}</div> <div style='background-color: teal; text-align: center'> <b>S3-Open Tickets</b>: ${findIssues(S1).size()}</div> """) def findIssues(String jqlSearch) { def searchService = ComponentAccessor.getComponent(SearchService) def issueManager = ComponentAccessor.getIssueManager() SearchService.ParseResult parseResult = searchService.parseQuery(botUser, jqlSearch) def searchResult = searchService.search(botUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()) def results = searchResult.results.key logs("Matching Issues : ${results}") return results } ApplicationUser executeWithUser() { ApplicationUser executingAdmin = ComponentAccessor.getUserManager().getUserByName(execUser) ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(executingAdmin) return executingAdmin } def logs(def lg) { def log = Logger.getLogger("com.onresolve.jira.groovy") logs(lg) }",
    scriptPathnull,
    parameters: { }
    },
    FIELD_STYLE_CLASSnull,
    name"Show a web panel"
    ]
    • }


Get required id of the fragment and then do a DELETE request call by using URI as below


Request Type: DELETE
URI: http://localhost:9090/rest/scriptrunner/latest/fragments/35317b57-d843-41b7-a80f-4d53514fd990


Please change the host url and id as per your instance.
That's it, fragment will be deleted and you can refresh Jira and it will work perfectly.



About Author
Muhammad Ramzan  is a certified Atlassian Consultant having 10+ years of professional experience in the area of DevOps, Software Testing(Manual/Automation) and Atlassian Tools Administration

1 Comments

  1. Can you provide detailed instructions on how to "Get required id of the fragment and then do a DELETE request call by using URI as below"

    Do you use postman or wget or something?

    ReplyDelete