Profile picture for user Christian Zanardi

Hello Community

I'm looking for a way to test if a file exists or not in the "LOCATION_COMMON_FILES"

Previously (version 9.x), it seems that the "getFile" function fire a try catch error in the file does not exists.

But it seems that it's not the case any more in 10.1.18 cloud edition

Any help ?

Thx in davance

Christian

by Nikita Martyanov
Posted on Wed, 08/31/2022 - 17:18

Hello Christian,

Since getFile returns an array of bytes the most simple way is to check its lenght. If length equals 0, then file doesn't exist.

var testFile = Context.getFile("test.xml", Constants.LOCATION_COMMON_FILES)
if (testFile.length>0) {
    ...
}

---

BR, Nikita

1
by Ralf Angeli
Posted on Mon, 09/05/2022 - 10:38

I just spoke with one of the devs and he confirmed that testing for a zero-length byte array is indeed the correct way to do this. The exception that was thrown in older releases was actually not supposed to happen.

0
by Christian Zanardi Author
Posted on Mon, 09/05/2022 - 15:09

Thank you both for your answer and your confirmation !!!

But I'm not sure this will be the answer in some cases. A zero length file can exists and may be lock by an other user than me....

Anyway, this is the Aris answer for the moment and for my purpose, i will first the "zero length" technic, but be carefull with the write rigth...

Meilleures salutations,
Christian

1
by Kay Fischbach
Posted on Mon, 11/07/2022 - 11:39

You can use the ScriptAdmin report component to explore the Common Files directory.

Example:

var nLocale = Context.getSelectedLanguage();
var scriptAdminComponent = Context.getComponent("ScriptAdmin");

function getCommmonCategoryComponentID() {
    var allScriptComponentInfos = scriptAdminComponent.getScriptComponents();
    
    for each(var scriptComponentInfo in allScriptComponentInfos) {
        if(scriptComponentInfo.getComponentName() == "common") {
            return scriptComponentInfo.getComponentID();
        }
    }
    
    throw new Packages.java.lang.IllegalStateException("Common script category not found");
}

function getCommonFileNames() {
    var commonScriptComponentID = getCommmonCategoryComponentID();
    
    var allScriptInfos = scriptAdminComponent.getScriptInfos(commonScriptComponentID, null, nLocale);
    
    function mapScriptInfoToName(someScriptInfo) {
        return someScriptInfo.getName();
    }
    
    return allScriptInfos.map(mapScriptInfoToName).sort();
}

var result = getCommonFileNames();

This creates a result array of file names from the Common Files directory.

You can find out more about this by taking a look at "Methods for reports and semantic checks" > "Global Objects" > "Report component interfaces" > "ScriptAdmin" in the ARIS Script documentation.

1

Featured achievement

Explorer
Take a tour! Learn more about the different ARIS Community areas and ARIS editions.
Recent Unlocks
  • YH
  • DK
  • PE
  • AG
  • IV
  • PacMan

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