Advertisement
atelbor

[GRVY] Fields Select

Dec 14th, 2022 (edited)
1,936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.94 KB | None | 0 0
  1. /****************************/
  2. /*   GRVY - Fields Select   */
  3. /****************************/
  4.  
  5. // Obtener el valor e id de un campo
  6. // Obtener las opciones de un campo
  7. // Setear el valor a un campo
  8. // Obtener el id de una opción de un campo
  9. // Mostrar solo ciertas opciones de las que dispone
  10.  
  11. /************************************************************************/
  12.  
  13. // Obtener el valor y/o id de un campo Select
  14. def testCf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10000")
  15. def testCfValue = ((Option) issue.getCustomFieldValue(testCf)).value
  16. def testCfOptionId = ((Option) issue.getCustomFieldValue(testCf)).optionId
  17. /************************************/
  18.  
  19. // Obtener las opciones de un campo
  20. def testCf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10000")    
  21. def testCfConfig = testCf.getRelevantConfig(getIssueContext())
  22. def testCfOptions = ComponentAccessor.getOptionsManager().getOptions(testCfConfig)
  23. /************************************/
  24.  
  25. // Setear el valor a un campo
  26. def testCfOption = testCfOptions.findAll { it.value in ["Opcion_1"] }
  27. issue.setCustomFieldValue(testCf, testCfOption)
  28. /************************************/
  29.  
  30. // Obtener el id de una opción de un campo
  31. if (ComponentAccessor.getOptionsManager().findByOptionValue(value)){
  32.     optionId = ComponentAccessor.getOptionsManager().findByOptionValue(value)[0].optionId.toString();
  33. }
  34. /************************************/
  35.  
  36. // Mostrar solo ciertas opciones de las que dispone
  37. //// Alternativa 01
  38. def testCfOptionsMap = testCfOptions.findAll { it.value in ["Opcion_1", "Opcion_2"] }
  39. selectListField.setFieldOptions(testCfOptionsMap)
  40.  
  41. //// Alternativa 02
  42. def testCfOptionsMap = testCfOptions.findAll { it.value in ["Opcion_1", "Opcion_2"] }
  43.     .collectEntries { [ (it.optionId.toString()): it.value ] }
  44. selectListField.setFieldOptions(testCfOptionsMap)
  45. /************************************/
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement