Forums

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

Clear form in JSM

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 16, 2022

Hi Guys,

I have a select list field called Agreement with values New & Existing, if the user selects Existing, the form prefills couple of fields with default values but if the user change the mind & select back New as an option, the prefilled values doesn't go away, I would like to clear all those values in one go, is there a method to clear entire form with null at once ?

I know, I can do it for each field one by one, but I would like to do it at once, is there a way to do that ? If yes, help with the information.

Thanks

 

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 16, 2022

There is no built-in clear form option in scriptrunner.

You have to either hard code each field to clear, or you can clear every field systematically with a loop:

I haven't tried, but something like this might work:

def agreementFld = getFieldByName('Agreement')
if (agreementFld.value == 'New') {
fieldScreen.tabs.each { tab ->
tab.fieldScreenLayoutItems.findAll {
it.fieldId != agreementFld.fieldId
}.each {
getFieldById(it.fieldId).setFormValue('')
}
}
}

 It should reset the form entry for all fields except the Agreement field.

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2022

Hi @PD Sheehan

Thanks for your reply but I am getting error as below when I am trying to clear field, could you please take a look.

Clear Fields Error.JPG

Thanks!

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2022

fieldChanged is a string that already represents the fieldId.

So you can use it like this: getFieldById(fieldChanged).

Then, you cna use the resulting formField object and access it's fieldId property.

But you can't access fieldChanged.fieldId since fieldChanged is a string and it won't have any properties to access.

You can try:

tab.fieldScreenLayoutItems.findAll { 
it.fieldId != changedField
}.each {
getFieldById(it.fieldId).setFormValue('')
}
Jeff Maynard
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 8, 2024

This works for the most part, but having issues with multi select fields not clearing with this approach.  Any ideas on how to clear multi-select fields?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events