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
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.
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.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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('')
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.