question

Chandler avatar image
0 Likes"
Chandler asked Chandler commented

Reference Treenode Properties from within a FlexScript Label

FlexSim Healthcare 23.0.2 (I know, there may be an upgrade available)

I am trying to associate equipment, staff, and locations based on similarities in their names. I would like to do this without the use of an additional table. The purpose is to control mismatches in resources that should be linked to another resource (the stretcher that belongs in an exam room, for example), and to automate the mapping of that linking when creating new instances (a copy of a resource with a sequential ID number would automatically point to a resource that should be associated, also having a new, sequential ID number)

I am trying to write two labels to perform this sort of function:

  1. 1. matches and ID number of an exam room name to an ID number of some equipment stored in this exam room (in this case, a stretcher)
  2. 2. Points to a registration terminal (location resource) based on an acquired registration clerk (staff resource).

Correct me if I'm wrong: When editing a flexscript label, it seems that I can access the Null variant that exists at a treenode, but because it is Null I can't access any of the properties or methods of that treenode.

1681932919417.png

1681932046138.png

Simply put, for the label I want to access the name of the staff from within the label. - in this case "Clerk_Registration_Front_1" - so that the resulting label can point to "Registration_Front_1" which is the name of the associated computer/registration station.

1681932226094.png1681932277883.png

Is this possible to do this way? Or, is there another way?

Thanks!

FlexSim 23.0.2
healthcare
1681932046138.png (45.0 KiB)
1681932226094.png (89.1 KiB)
1681932277883.png (183.6 KiB)
1681932919417.png (46.5 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Chandler commented

Your code isn't working because you need to assign a value to current before using it. To reference the label's object use a line like this:

Object current = ownerobject(c);

(Also your regex in that example returns _Registration_Front_1 not _Front_1)

However, instead of putting code like this on the label of every object I would just create connections between objects. For example, this code that you can run from a Debug Console will find any staff that have the name of a location embedded in their name and create a Location label on them that points at that location:

Array allStaff = Group("Staff").toFlatArray();
Array allLocations = Group("Locations").toFlatArray();

for (int i = 1; i <= allLocations.length; i++) {
    Object location = allLocations[i];
    for (int j = 1; j <= allStaff.length; j++) {
        Object staff = allStaff[j];
        if (staff.name.includes(location.name))
            staff.Location = location;
    }    
}
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Chandler avatar image Chandler commented ·

Ok this is interesting.

I like the code you have written there. I think we could implement something like that but I am working with team members that aren't technical enough to implement code while I'm not around ... so as much as it pains me I'm trying to stay away from asking them to run a script.

That said I think either way would work, and if more scripting becomes necessary then I may just put together a startup script and call it "blackbox" or something.

ownerobject(c) is the piece of info I was looking for, and after simplifying/correcting my code that does work.

I hadn't realized that I was asking regex to return any number of the group _. - so I got more explicit with my ask and used the following to capture everything after Registration:

  • /[A-Za-z0-9]*_+[A-Za-z0-9]*_+[0-9]*$/g

We'll have to get smarter with naming in short order anyway in order to make either approach work...

Thanks!

0 Likes 0 ·