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
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