This is an old revision of the document!
Example for a Dataset Script
This example illustrates how the Staes Javascript API is working.
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(); } }
Let's take a look in more detail to this script:
var artifacts = pkit.getCurrentProject().getEntities("containsProcess@SYSTEM") [0].getEntities("containsArtifact@SYSTEM");
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>.