question

Eva R2 avatar image
0 Likes"
Eva R2 asked Felix Möhlmann edited

Using a global variable in a condition

Each flow item is assigned with a label "DateNumber" with a random number associated with it. I have created a global variable called "CurrentDate" and assigned it with a specific value. I want my processor to pull from a global list based on the specific DateNumber. For example I will use the number "123". My model works when I use the pull strategy of pulling from a list with the requirement "WHERE DateNumber = 123". However, even though my global variable is set to the value "123" if I use the expression "WHERE DateNumber = CurrentDate" the processor doesn't take any flow items. I have also tried using "==" instead of just "=". I hope this made sense - can anyone help?

FlexSim 19.2.4
processorlistflexsim 19.2.4global variablesconditional
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

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Felix Möhlmann edited

The Sql query consists of a string and can't automatically interpret variables. So in your case, it's looking for an item where the value of "DateNumber" is "CurrentDate".

Normally in a query you write in code, you can pass in variables as parameters. But in this case the query is part of the pull command and I don't know if that is possible in this case.

There is a way to get it working though.

Open the code window of the pull strategy. In there find the line that start with "string queryStr = ".
Delete everything after the "=" and instead write

"WHERE DateNumber = " + string.fromNum(CurrentDate);

This adds the value of your variable as a string onto the query and you now see the same result as if you entered the value directly.

customquerystring.png

I only tested this in version 19.1, as i don't have 19.2 installed right now, but it should still work.


· 3
5 |100000

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

Eva R2 avatar image Eva R2 commented ·
Thank you so much - this worked!
0 Likes 0 ·
Eva R2 avatar image Eva R2 commented ·
Do you have any advice on what I should change if I wanted to compare the values using less than, greater than, etc.?
0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Eva R2 commented ·

Sure, you can just replace the "=" after "DateNumber" in that line with any of "<", ">", "<=" or ">=".

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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