MF

 

Hi Community,

I am quite new to scripting in ARIS BA and struggle with the conversion of old VBA scripts. One topic that causes frequent issues is determing the length of an object list (I guess it is called ABOSubjectList) after deleting some of the objects. E.g. the script creates a list of object occurences like this:

oobjocclist.value = omodel.ObjOccListFilter(Constants.OT_FUNC)

But then I need to delete some of the occurences from the list e.g. because they are inactive, have the wrong symbol or whatever. The converted script does it usually by the delete function defined in the convertertools.js . It looks like this with "k" being just the index of the object that is being deleted:

oobjocclist= __delete(oobjocclist, k)

This works quite well but afterwards I am not able to find out the length of the object list. Usually I am using:

oobjocclist.value.length

but after having deleted some elements it causes an error like "TypeError: Cannot read property "length" from undefined". In most cases I have found a workaround like reading the length into a variable upfront but in some cases this is not possible/ bothersome. Any ideas how to avoid this error? Would it be better to transform the object list into an array first and then work with the array (not sure I am able to do this either)?

Any suggestions or sample code is greatly appreciated.

Cheers,

Martin

by Vladimir Bis
Posted on Thu, 03/22/2012 - 16:36

Hi Martin,

why do you use value property?

ObjOccListFilter

get you array of functions, so you can use 

oobjocclist.length

only.

0
by Martin Felder Author
Posted on Thu, 03/22/2012 - 16:43

Hi Vladimir,

Yes, I was wondering about this as well. I think this was done automatically by converting the VBA script into Java. But sometime I have it with value, sometimes without. I'll try it without .value.

Thanks,

Martin

0
by Martin Felder Author
Posted on Thu, 03/22/2012 - 18:00

Ah - I think I got it. Somehow this "__delete" function from the convertertool is creating a mess. If I have understood it correctly it just moves the object that shall be deleted to the end of the array and then reduces the length of the array by one. Like the following with "arr" being the objectlist and "obj" the object to be deleted: 

if(arr[i]==obj) {
        for(j=i+1;j<arr.length;j++) {
          arr[j-1] = arr[j];
        }
        arr.length = arr.length - 1;

Anyway - I am going to avoid this function. Instead "splice" just works perfectly. In my case:

oobjocclist.splice(k,1);

It removes one (1) object from the array at the position of k - so easy!

And Vladimir, you have been right. The value property was nonsense. This pointed me in the right direct to see what other methods are available for arrays. Thanks for the hint!

Best regards, Martin

0
by Vladimir Bis
Posted on Fri, 03/23/2012 - 08:11

Hi Martin,

one more thing - try to delete occurences by Occ.Remove() method and I recommend you to decrement variable in for loop:

for (i = oobjocclist.length - 1; i >= 0; i--)
     Occ.Remove();
0
by Martin Felder Author
Posted on Fri, 03/23/2012 - 10:25

Thanks Vladimir, good point. But in this case I want to keep the occurence in the model, I just want to delete the object from the array as it is not needed for further operations in the script.

Martin

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