Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
72:custom_reports_getting_started_example [2019/02/07 14:31] – created ext-bkkr | 72:custom_reports_getting_started_example [2024/02/15 00:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Example for a Dataset Script ====== | ====== Example for a Dataset Script ====== | ||
+ | |||
+ | This example illustrates how the Staes Javascript API is working. | ||
+ | |||
+ | < | ||
+ | var artifacts = | ||
+ | | ||
+ | [0].getEntities(" | ||
+ | for (i = 0; i < | ||
+ | var artifacts_instances = | ||
+ | | ||
+ | for (j = 0; j < | ||
+ | var artifacts_revisions = | ||
+ | | ||
+ | if (artifacts_revisions.length == 0) { | ||
+ | | ||
+ | } else { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Let's take a look in more detail to this script: | ||
+ | |||
+ | < | ||
+ | var artifacts = | ||
+ | | ||
+ | [0].getEntities(" | ||
+ | </ | ||
+ | |||
+ | We use the global variable pkit to call the method getCurrentProject() to get a handle on the project of the current metric. The method returns the current project. | ||
+ | |||
+ | Now we call the method getEntities() with the parameter " | ||
+ | |||
+ | And now we try to get all Artifacts which are available in the process. So we call getEntities() with the parameter " | ||
+ | |||
+ | < | ||
+ | for (i = 0; i < | ||
+ | var artifacts_instances = | ||
+ | | ||
+ | </ | ||
+ | |||
+ | Now we iterate through all artifacts to get the instances of the artifacts, that means the configuration management controlled files. So we call getEntities() with the parameter " | ||
+ | |||
+ | < | ||
+ | for (j = 0; j < | ||
+ | var artifacts_revisions = | ||
+ | |||
+ | | ||
+ | </ | ||
+ | |||
+ | Now we do the same with the revisions of an instance. Each instance has several revisions. But as you can see later we use only one revision, the latest one. As a result we have a variable with all revisions artifacts_revisions. | ||
+ | |||
+ | < | ||
+ | if (artifacts_revisions.length == 0) { | ||
+ | | ||
+ | } else { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Now we check if a revision exists for an instance. If not then we fill the State column by calling the method dataset.setColumnValue() with a string "no version" | ||
+ | |||
+ | < | ||
+ | dataset.setColumnValue(" | ||
+ | | ||
+ | </ | ||
+ | |||
+ | We retrieve the document name from the property " | ||
+ | |||
+ | The last action to perform is to save the row by calling the method dataset.storeResultRow() with the two columns " | ||
+ | |||
+ | < | ||
+ | dataset.storeResultRow(); | ||
+ | </ | ||