0

I would like to change the values of a few custom fields of some work items from a Javascript (or Velocity), but I've not managed to find a solution yet. I can read the custom fields via the $wi.fields.get("MyCustomField").get() method but I don't know if it's possible to change their values?

Thanks

1 Answers1

1

If you are ok to use the classic Polarion API. changing Custom fields is quite straight forward:

$wi.setValue("CustomFieldId", $value)

Note that $value needs to be an object fitting to the definition of the custom field. So in simplest case a string, a boolean or a number, but could also be a Text-object, or an EnumOption.

Peter Parker
  • 29,093
  • 5
  • 52
  • 80
  • Thanks for your reply Peter. Do you know if this is usable via a Page script / script block in Polarion? I keep getting the 'Is not a valid reference' error when I try this inside a page script. I'm assuming I'm doing something wrong because even for the '$wi.fields.get("MyCustomField").get()' I have to call this inside a for loop otherwise I get the same reference error. – Julien Llanes Dec 16 '22 at 09:08
  • Also I should've mentioned that I'm trying this inside a LiveDoc page script. – Julien Llanes Dec 16 '22 at 12:05
  • For example I don't understand why if I do `$wi.getId()` it returns the ID fine, but if I do `$wi.getTitle()` this doesn't work? – Julien Llanes Dec 16 '22 at 13:26
  • 1
    Yes this should also work in a liveDoc page, however you should _not_ set custom fields inside a livedoc page. I do not know why you do not get the title, but I assume you have a wrong instance of $wi. you can always check the type with outputting $wi.class.name – Peter Parker Dec 17 '22 at 18:53
  • Could you tell me what the reason for not setting custom fields inside LiveDocs is? What I'm trying to do is save a bunch of 'settings' of a KPI dashboard page made with mostly JS, and I'm using another Polarion project with work items 'KPI' to save the various settings inside custom fields of each. This works fine, but I'd like to be able to change those settings directly where the dashboard is, with the .setValue() method for instance. I checked the class of the $wi, and it returned 'Workitem', which sounds ok? – Julien Llanes Dec 19 '22 at 08:58
  • This is the code I'm testing: `#set($wi = $trackerService.getWorkItem("kpi","KPI-1")) #set($kpiGet = $wi.fields.get("kpi").get()) wi.getId: $wi.getId()
    kpiGet: $kpiGet
    ##wi.getTitle: $wi.getTitle()
    wiClass: $wi.class.name `
    – Julien Llanes Dec 19 '22 at 08:59
  • and the result: `wi.getId: KPI-1 kpiGet: $kpiGet wiClass: com.polarion.alm.tracker.internal.model.WorkItem` – Julien Llanes Dec 19 '22 at 08:59
  • When I uncomment the .getTitle() I get this error: _ERROR Method getTitle threw exception for reference $wi in template at [6,14] ERROR Invocation of method 'getTitle' in class com.polarion.alm.tracker.internal.model.WorkItem threw exception class com.polarion.platform.persistence.UnresolvableObjectException : uri: subterra:data-service:objects:/default/kpi${WorkItem}KPI-1_ – Julien Llanes Dec 19 '22 at 09:00
  • usually a UnresolvableObjectException means the object in question (here the WI with id KPI-1) is not available either because of index problems (reindex is an option) or because the item was deleted – Peter Parker Dec 23 '22 at 08:25
  • Ok thanks @Peter, I'll try a re-index in the new year. It's weird though because I can read custom fields from KPI-1, just not write to it via .setValue(). – Julien Llanes Dec 24 '22 at 16:33
  • I have received this from the support guys: Velocity widgets can't edit data in Polarion. I would need a Servlet or a Java widget. If this makes sense to you, I'll close this question with it. – Julien Llanes Jan 30 '23 at 15:56