Forums

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

Autofill the Labels field based on priority field

Lakshmi CH
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.
September 30, 2021

Hi Team,

 We have scenario If the ticket priority is critical - automatically add a Priority1 to Label field. If the ticket is any other priority add a Priority2 value to Label field.

The below code is working, but while creating the ticket the priority default value is Minor, so the ticket is updating with Label ="Priority2" as per the requirement, and when i am changing the priority to "Critical on the same page, the Label field values are updating to both "Priority1" and "Priority2"  if the priority value is Critical, the Label should be updated to Priority1.

Is there any possibility to clear the Label field when we changing the priority values. For example if the Ticket is minor, Label is "Priority2", and changing the priority to Critical, it should clear the Priority2 and update the Priority1 label value.

Please check the attached screenshots for your reference.

def priorityField = getFieldById(getFieldChanged())
def labelsField = getFieldById("labels")

String priorityVal = priorityField.getValue().getName()

if(priorityVal.equals("Critical")){
labelsField.setFormValue('Priority1')
} else {
labelsField.setFormValue('Priority2')
}

 

s1.PNG

1 answer

0 votes
Tuncay Senturk _Snapbytes_
Community Champion
October 1, 2021

I am not sure but can you try this one?

 

if(priorityVal.equals("Critical")){
labelsField.setFieldOptions(["Priority1"])
labelsField.setFormValue(['Priority1'])
} else {
labelsField.setFieldOptions(["Priority2"])
labelsField.setFormValue(['Priority2'])
}
Lakshmi CH
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.
October 1, 2021

No @Tuncay Senturk _Snapbytes_ . Its not working, no value is displaying in the labels field.

Tuncay Senturk _Snapbytes_
Community Champion
October 1, 2021

Did you not forget the square brackets, did you? I already tried in my environment and it worked.

 

['Priority1'] rather than 'Priority1'

Lakshmi CH
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.
October 1, 2021

Hi @Tuncay Senturk _Snapbytes_ , Thanks much for your quick replies. Yes. I tried with the following. Actually its clearing the field value. When i am giving Label is Priority1 manually , and selecting other priority its clearing the value in the label field.

def priorityField = getFieldById(getFieldChanged())
def labelsField = getFieldById("labels")

String priorityVal = priorityField.getValue().getName()

if(priorityVal.equals("Critical")){
labelsField.setFieldOptions(["Priority1"])
labelsField.setFormValue(['Priority1'])
} else {
labelsField.setFieldOptions(["Priority2"])
labelsField.setFormValue(['Priority2'])
}

Tuncay Senturk _Snapbytes_
Community Champion
October 1, 2021

Sorry, I am not an expert on this, but this was the first solution that came to my mind.

That's interesting, as it works in my environment.

Suggest an answer

Log in or Sign up to answer