I want to write a simple script to get me all objects created in a model along with the following attributes: creater, last updated and last updated by..
please advise or refer me to tutrial
I want to write a simple script to get me all objects created in a model along with the following attributes: creater, last updated and last updated by..
please advise or refer me to tutrial
Hi,
I'll guide you through the process:
Create a new ARIS Report, fill out the name, topic, author, ... .
Your script doesn't open dialoges and doesn't need write access, so leave those checkboxes unticked.
In which way your script should be available is your decision, set the tickboxes for ARIS client and ARIS connect access accordingly.
On the next page you're asked for a context. Set a tick next to "Model" and configure which model types this is supposed to work with, or leave it as-is to make it available for all model types.
On the next page tell it you want to create an output file. I'm pretty sure your task could be achieved with the what-you-see-is-what-you get editor with out any manual coding, but you specifically said you want to "write a simple script", therefore you probably want to opt for the code view on that page to write your report program from scratch.
Output format for starters can be txt - it's simple to write into txt files.
The remaining two pages are your coice, the output format and access limitations are nothing I can tell you much about.
Once you finished your report creation it'll give you a blank script and that's where the coding starts:
- The attributes you mentioned are mostly language independent, but ARIS still wants to know in which language you want them, so start off with making this information easily accessible in your code:
var nLocale = Context.getSelectedLanguage();
This gets the language the script user is currently logged in with into the database and assigns it to a variable called nLocale.
- At the start of your script you can also define your output object, which you'll use to write into your output file:
var oOutput = Context.createOutputObject();
This creates an output object in some way the script user wanted it to be.
- Then it's time to get the model you selected
var selModel = ArisData.getSelectedModels()[0];
ARIS by default gives you the option to select multiple models as a script context, so getSelectedModels() returns an array of selected models. With [0] at the end you tell it to only give you the first (and in your case only) element of this result array.
- Now you can retrieve all object occurrences of your selected model:
var allOcc = selModel.ObjOccList();
That one is pretty straightforward - you previously told it that selModel is your selected model, you use a method from that and you got yourself your occurrences.
- After that it's time for a more advanced Javascript technique "for each(... in ...)" - a loop.
You want to iterate through the object occurrences and output something for every single one of them.
So the next block will look like this
for each(var singleOcc in allOcc) { //Code goes here }
Note the "Code goes here" comment - you'll have to put two line there - one that makes outputting information easier and another one that that tells the output object to wite something to your output file.
- The first of those lines is
var singleObjDef = singleOcc.ObjDef();
Information like attribute values isn't stored in object occurrences - those are just information anchor points that basically tell ARIS that there is information at a specific position in a model. The actual information is stored in object definitions - you acess them as shown in the code above.
- The second of those lines is a long one - not necessarily because it's a complicated one - stuff repeats - but because you want to know 4 things
oOutput.OutputTxt(singleObjDef.Name(nLocale) + " | " + singleObjDef.Attribute(Constants.AT_CREATOR, nLocale).getValue() + " | " + singleObjDef.Attribute(Constants.AT_LAST_CHNG_2, nLocale).getValue() + " | " + singleObjDef.Attribute(Constants.AT_LUSER, nLocale).getValue() + "\n");
oOutput is the output object you defined. OutputTxt is the method that tells it to write something to the output file.
singleObjDef is the previously defined object definition, .Name(nLocale) returns the name of that object - this attribute actually isn't language independent, therefore it absolutely makes sense that you give it the nLocale you defined at the start of your script.
After that stuff repeats three times - your're basically building a string by connecting information. singleObjDef is again the previously defined object definition, .Attribute(attributeTypeNumber, locale) allows you to access an attribute of that object definition. Instead of hard-coding attribute type numbers into the script I opted for using the ARIS API names of those attributes, you can find them in your ARIS client > "Administration" tab > "Configuration" > "Method" > "Attribute types" > the column labeled "API-Name". As I said the attributes you're asking for are language independent, but for the sake of consistency ARIS wants to know the asked for locale every time no matter what attribute you ask for. getValue() simply gets you the attribute value in string form, for certain attributes like the last modification date you could also get it in a Java date format e.g. if you want to calculate time with it - but you just want to output information and for that you need a string.
- Well only one last thing left (after the closing of your for each loop), actually writing your output file - everything you've done so far was only done "in-memory"
oOutput.WriteReport();
Your entire script will look something like this:
var nLocale = Context.getSelectedLanguage(); var oOutput = Context.createOutputObject(); var selModel = ArisData.getSelectedModels()[0]; var allOcc = selModel.ObjOccList(); for each(var singleOcc in allOcc) { var singleObjDef = singleOcc.ObjDef(); oOutput.OutputTxt(singleObjDef.Name(nLocale) + " | " + singleObjDef.Attribute(Constants.AT_CREATOR, nLocale).getValue() + " | " + singleObjDef.Attribute(Constants.AT_LAST_CHNG_2, nLocale).getValue() + " | " + singleObjDef.Attribute(Constants.AT_LUSER, nLocale).getValue() + "\n"); } oOutput.WriteReport();
If you don't understand a step or just simply want me to explain it in a different way (break it down more) feel free to ask. This was just the "quick & easy" approach - a "simply script" you called it.
Hi,
I'll guide you through the process:
Create a new ARIS Report, fill out the name, topic, author, ... .
Your script doesn't open dialoges and doesn't need write access, so leave those checkboxes unticked.
In which way your script should be available is your decision, set the tickboxes for ARIS client and ARIS connect access accordingly.
On the next page you're asked for a context. Set a tick next to "Model" and configure which model types this is supposed to work with, or leave it as-is to make it available for all model types.
On the next page tell it you want to create an output file. I'm pretty sure your task could be achieved with the what-you-see-is-what-you get editor with out any manual coding, but you specifically said you want to "write a simple script", therefore you probably want to opt for the code view on that page to write your report program from scratch.
Output format for starters can be txt - it's simple to write into txt files.
The remaining two pages are your coice, the output format and access limitations are nothing I can tell you much about.
Once you finished your report creation it'll give you a blank script and that's where the coding starts:
- The attributes you mentioned are mostly language independent, but ARIS still wants to know in which language you want them, so start off with making this information easily accessible in your code:
var nLocale = Context.getSelectedLanguage();
This gets the language the script user is currently logged in with into the database and assigns it to a variable called nLocale.
- At the start of your script you can also define your output object, which you'll use to write into your output file:
var oOutput = Context.createOutputObject();
This creates an output object in some way the script user wanted it to be.
- Then it's time to get the model you selected
var selModel = ArisData.getSelectedModels()[0];
ARIS by default gives you the option to select multiple models as a script context, so getSelectedModels() returns an array of selected models. With [0] at the end you tell it to only give you the first (and in your case only) element of this result array.
- Now you can retrieve all object occurrences of your selected model:
var allOcc = selModel.ObjOccList();
That one is pretty straightforward - you previously told it that selModel is your selected model, you use a method from that and you got yourself your occurrences.
- After that it's time for a more advanced Javascript technique "for each(... in ...)" - a loop.
You want to iterate through the object occurrences and output something for every single one of them.
So the next block will look like this
for each(var singleOcc in allOcc) { //Code goes here }
Note the "Code goes here" comment - you'll have to put two line there - one that makes outputting information easier and another one that that tells the output object to wite something to your output file.
- The first of those lines is
var singleObjDef = singleOcc.ObjDef();
Information like attribute values isn't stored in object occurrences - those are just information anchor points that basically tell ARIS that there is information at a specific position in a model. The actual information is stored in object definitions - you acess them as shown in the code above.
- The second of those lines is a long one - not necessarily because it's a complicated one - stuff repeats - but because you want to know 4 things
oOutput.OutputTxt(singleObjDef.Name(nLocale) + " | " + singleObjDef.Attribute(Constants.AT_CREATOR, nLocale).getValue() + " | " + singleObjDef.Attribute(Constants.AT_LAST_CHNG_2, nLocale).getValue() + " | " + singleObjDef.Attribute(Constants.AT_LUSER, nLocale).getValue() + "\n");
oOutput is the output object you defined. OutputTxt is the method that tells it to write something to the output file.
singleObjDef is the previously defined object definition, .Name(nLocale) returns the name of that object - this attribute actually isn't language independent, therefore it absolutely makes sense that you give it the nLocale you defined at the start of your script.
After that stuff repeats three times - your're basically building a string by connecting information. singleObjDef is again the previously defined object definition, .Attribute(attributeTypeNumber, locale) allows you to access an attribute of that object definition. Instead of hard-coding attribute type numbers into the script I opted for using the ARIS API names of those attributes, you can find them in your ARIS client > "Administration" tab > "Configuration" > "Method" > "Attribute types" > the column labeled "API-Name". As I said the attributes you're asking for are language independent, but for the sake of consistency ARIS wants to know the asked for locale every time no matter what attribute you ask for. getValue() simply gets you the attribute value in string form, for certain attributes like the last modification date you could also get it in a Java date format e.g. if you want to calculate time with it - but you just want to output information and for that you need a string.
- Well only one last thing left (after the closing of your for each loop), actually writing your output file - everything you've done so far was only done "in-memory"
oOutput.WriteReport();
Your entire script will look something like this:
var nLocale = Context.getSelectedLanguage(); var oOutput = Context.createOutputObject(); var selModel = ArisData.getSelectedModels()[0]; var allOcc = selModel.ObjOccList(); for each(var singleOcc in allOcc) { var singleObjDef = singleOcc.ObjDef(); oOutput.OutputTxt(singleObjDef.Name(nLocale) + " | " + singleObjDef.Attribute(Constants.AT_CREATOR, nLocale).getValue() + " | " + singleObjDef.Attribute(Constants.AT_LAST_CHNG_2, nLocale).getValue() + " | " + singleObjDef.Attribute(Constants.AT_LUSER, nLocale).getValue() + "\n"); } oOutput.WriteReport();
If you don't understand a step or just simply want me to explain it in a different way (break it down more) feel free to ask. This was just the "quick & easy" approach - a "simply script" you called it.
I really cannot thank you enough, came across this explanation and I must say you helped me big time with this great explanation.