Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revisionBoth sides next revision
72:custom_reports_getting_started_example [2019/02/07 14:31] – created ext-bkkr72:custom_reports_getting_started_example [2019/02/15 19:28] ext-bkkr
Line 1: Line 1:
 ====== Example for a Dataset Script ====== ====== Example for a Dataset Script ======
 +
 +This example illustrates how the Staes Javascript API is working.
 +
 +<code>
 +var artifacts =
 + pkit.getCurrentProject().getEntities("containsProcess@SYSTEM")
 +[0].getEntities("containsArtifact@SYSTEM");
 +for (i = 0; i <artifacts.length; i++) {
 + var artifacts_instances =
 + artifacts[i].getEntities("containsInstance@SYSTEM");
 + for (j = 0; j <artifacts_instances.length; j++) {
 + var artifacts_revisions =
 + artifacts_instances[j].getEntities("containsRevision@SYSTEM");
 + if (artifacts_revisions.length == 0) {
 + dataset.setColumnValue("State", "no version");
 + } else {
 + dataset.setColumnValue("State",
 + artifacts_revisions[0].getProperty("state"));
 + }
 + dataset.setColumnValue("DocumentName",
 + artifacts_instances[j].getProperty("LogicalName"));
 + dataset.storeResultRow();
 +}
 +}
 +</code>
 +
 +Let's take a look in more detail to this script:
 +
 +<code>
 +var artifacts =
 + pkit.getCurrentProject().getEntities("containsProcess@SYSTEM")
 +[0].getEntities("containsArtifact@SYSTEM");
 +</code>
 +
 +We use the global variable pkit to call  the method <font inherit/Courier New,Courier,monospace;;inherit;;inherit>getCurrentProject()</font> to get a handle on the project of the current metric. The method returns the current project.
 +
 +Now we call the method <font inherit/Courier New,Courier,monospace;;inherit;;inherit>getEntities()</font> with the parameter "<font inherit/Courier New,Courier,monospace;;inherit;;inherit>containsProcess@SYSTEM</font>" to retrieve the process on this project. The return is an array, but we mostly want to get the current view, we use the first one by [0].
 +
 +And now we try to get all Artifacts which are available in the process. So we call <font inherit/Courier New,Courier,monospace;;inherit;;inherit>getEntities()</font> with the parameter "<font inherit/Courier New,Courier,monospace;;inherit;;inherit>containsArtifact@SYSTEM</font>" to retrieve the artifacts on this process. As a result we get an array of all artifacts in the variable <font inherit/Courier New,Courier,monospace;;inherit;;inherit>artifacts</font>.