MP

Hello everyone

I can call a function with its full name as I can do in SQL ([ServerName].[DatabaseName].[Scheme].[Table])?

for instance

file: CommonFunctions.js

function1();

function2();

etc.

In a different script can I call the function as CommonFunctions.function1()?

Can this be done?

Thanks

Marco

by Kay Fischbach
Posted on Thu, 08/29/2019 - 11:56

Hi Marco,

Javascript doesn't treat different files as different objects, so no you can't call a function of a different script (file) with ScriptfileName.functionName().

It is however pretty simple to use functions of a different file. You just have to tell ARIS to load the additional file beforehand, and then you can use the function in your main script just by using functionName() - just like you would do it if the method was written in your main script to begin with.

The "telling ARIS which files to load" is straightforward:

  1. Open your report script properties (for example when you see your report script open the "Contents" tab at the top and there is a button called "Properties").
  2. The first page of the "Properties" wizard is called "General". There in the bottom right corner you can find a Button "Advanced...". Click that.
  3. The "Advanced options" single page sub-dialog opens, and you get a list of other reports you've written, as well as files you've uploaded to the "Common files" section of ARIS. Tick the CommonFunctions.js file that contains your function1 method and confirm the sub-dialog and dialog changes with the OK buttons. Don't ask me what the "Resource usage" section in the sub dialog is needed for, I don't know that.

That's it, you can now use function1() in your script as if the method was written in your main script.

Note that your main script is loaded last, so if you define a function1() in your main script it will completely overwrite the function1() from the .js file and there is no way to access that method. This is quite an interesting mechanic people can make use of when writing userscripts (Wikipedia - Userscript), but may not be desirable for your ARIS needs. Just give all of your functions distinct names and you won't run into any such problems.

0
by M. Zschuckelt
Posted on Fri, 08/30/2019 - 10:03

Hi, you can achieve that with normal JavaScript language features. Start with including your CommonFunctions.js as Kay described it.

In your CommonFunctions.js you define a global Object

CommonFunctions = {}

And then you define all your functions in CommonFunctions.js as members of that object:

CommonFunctions.function1 = function() {

// your code

}

Then in your main scripts you can access the function from your library script as

CommonFunctions.function1();

If you do not want to modify your CommonFunctions.js such that compability breaks with other scripts already using it, you can also leave all functions in it as is, but you additionally add them as members of the CommonFunctions object at the end of the script:

CommonFunctions.function1 = function1;

CommonFunctions.function2 = function2; //etc.

This way you have both options of accessing your functions from the common script. And if for example the name function2 is overloaded in your main script, it remains accessible via CommonFunctions.function2()

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock