Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Build URL to prepopulate field on JSM portal form

Sandhya Muthukumar February 10, 2025

I am trying to build a URL that prepopulates fields on a JSM form.

I have a select list field and a custom asset field that I want to populate using the following format:

<jiraBaseURL>/servicedesk/customer/portal/<id>/create/<formid>?customfield_xxxxx=<value>&customfield_yyyy=<key>

In this format, customfield_xxxxx represents the select list field. Although it works when I provide the option ID instead of the actual value, validation fails for the issue, resulting in an error requiring the field to be filled even when there is a value prepopulated in the field.

Additionally, customfield_yyyy=<key> is the asset field, and <key> represents the object key. However, this does not populate any values in the field.

Please suggest a way to prepopulate the custom fields using a URL in the JSM portal form

1 answer

0 votes
Florian Bonniec
Community Champion
February 11, 2025
Sandhya Muthukumar February 11, 2025

Thank you @Florian Bonniec 

I did go over the link but the link do not have the answer I was looking for.

 

Florian Bonniec
Community Champion
February 11, 2025

Base on the documentation Asset is not supported.

https://confluence.atlassian.com/servicemanagementserver/setting-up-request-types-939926357.html#Settinguprequesttypes-URLsSetupURLswithauto-populatedrequestfields

If you have script runner you could try to get the url content and force the field to be populated.

 

import com.atlassian.jira.component.ComponentAccessor

def url = request.getHeader("referer")
def url_params = url.substring(url.indexOf("?") + 1)
def string_params = url_params.tokenize('&')*.tokenize('=').collectEntries()
string_params.each{ k,v ->
if(getFieldById(k.toString()) != ''){
getFieldById(k.toString())?.setFormValue(v.toString())
}
}

You will probably have to create a function to get the proper content to set instead v.toString()

Regards

 

 

Sandhya Muthukumar February 11, 2025

I will try to run the script on the environment. 

What does 'k' and 'v' refer to in the script?

Thank you.

Florian Bonniec
Community Champion
February 11, 2025

k is the field id ex customfield_XXXXX

v is the value set in the url customfield_XXXXX=YYYY

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events