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

Scriptrunner custom screen on customer portal using script fragment

Athar Agha June 27, 2022

Hi - probably a basic question as i'm just getting to grips with scriptrunner.. 

We are building an issue hierarchy from one of our service desk portals.  One of the tasks is to allow a user to create a linked issue with certain user-entered fields, from the parent issue.  Essentially a button on the customer portal, that goes to a custom screen, which allows the user to input a few required fields, and then create the linked issue.  This works fine in agent view & we can achieve this using normal Jira functionality

however I'm trying to get this working as a customer

I've tried creating a 'constrained create issue' web part, which does allow a transition to a the create issue screen for the issue type.. not quite custom but it'll do.. when clicking the button - but the conditional validation doesn't work (it looks like the jiraHelper object isn't available in the customer portal).   So I'm looking for a bit of advice on the jiraHelper issue? or if anyone's done something similar in the customer portal and has a much better way of doing this that would be fantastic

The basic idea is: in the customer portal view of an issue -> click a button -> add in some specific information -> create & link a new issue.


1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 27, 2022

The question is basic... but not the solution.

I'm not aware of any built-in way to prompt customers for additional information on a request.

There might be add-ons that offer some forms, but the only built-in form is the new request form.

From scriptrunner standpoint, you might be able use the Web Item with "run code and display a dialog" method (this won't work with Refined for JSM). 

But you'd need to build a custom dialog2 form in HTML and serve it as custom rest endpoint.
And you'd need to write javascript to call an api (built-in or custom depending on your need) to create the linked issue.

Athar Agha June 29, 2022

Thanks for your reply! I'd rather not build a custom form in HTML and run a custom rest endpoint etc. as that would be quite cumbersome to maintain, as well as not be compatible with refined (which we're looking to implement at some point as well!) .. 

Any thoughts on why the jiraHelper object isn't available through the portal? something that I should raise with Adaptavist themselves or is this 'expected behaviour'?

I've heard Actions for Jira has this functionality, but it takes time to onboard a new plugin / plugin vendor as we have a governance process in place to ensure we don't just go wild and expose our data / cost money without due cause.. 

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 29, 2022

I've been meaning to reach out to Refined about the availability of the dialog2 (and many other AUI components) in their javascript layer to be able to implement custom dialog etc.

Yes, the availability of jiraHelper in the portal is probably a question for adaptavist.

But I'm not sure that would help you. I don't think you can get the "constrained create issue" would work in this case, it is designed to work within jira with jira permission.

I don't think it would work with portal permissions even if you were able to trigger it to pop up.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 20, 2022

So as it turns out, enabling the dialog2 functionality in Refined is all on our end.

And it's not all that hard

Here is a sample javascript that you can post via "install web resource" fragment in the context "refined.customer-portal":

//load the dialog functionality
WRM.require('wrc!com.atlassian.auiplugin:dialog2').done(function(){
console.log('Loaded AJS.dialog2', AJS.dialog2);
});
//add additional aui components you might want to use in the loadl
WRM.require('wrc!com.atlassian.auiplugin:aui-toggle').done(function(){
console.log('Loaded aui-toggle');
});

//bind click events on SR webItems to get and display a dialog
AJS.toInit(function () {
var srWebItemelector = '[id^="com.onresolve.jira.groovy.groovyrunner"]'
AJS.$('body').on('click', srWebItemelector, function(clickEvent){
clickEvent.preventDefault();
var href = AJS.$(this).attr('href');
AJS.$.ajax({
type: "GET",
dataType: "html",
url: href
}).done(function(data) {
AJS.dialog2(AJS.$(data)).show();
}).fail(function(jqXHR, textStatus, errorThrown) {
console.warn("Failed to execute remote:", errorThrown);
});
});
});

//add an icon to the custom webitem
AJS.$(document).ajaxStop(function () {
var webItemsParams = [
{menuText:'WebItem MenuText Example', iconClass:'rw_external_helper_icon_escalate'}
]
webItemsParams.forEach((webItem,index)=>{
if(webItem.iconClass){
var itemSelector = `.rw_item_content:contains(${webItem.menuText})`
var item = AJS.$(itemSelector)
item.prev('.rw_item_icon:not(.rw_external_helper_icon_escalate)').addClass(webItem.iconClass)
}
});
})

This will find all the ScriptRunner Web Items and bind an appropriate event to the item so that it will open a dialog instead of navigating to another page. The web item will need to specify "do nothing - you will use js to bind an action".

The second part of the script is optional, but it will add an icon to a specific web item by looking it up by its Menu Text.

TAGS
AUG Leaders

Atlassian Community Events