question

Amy M3 avatar image
0 Likes"
Amy M3 asked Jason Lightfoot edited

Can you use an If statement on a list?

I have a list and I want to add up some columns. There is one column(with arrow) I only want to add in if the recipes match(circled columns). Is it possible to do an If statement on an expression in a list? I can't seem to get it to work without errors.

FlexSim 21.1.0
flexsim 21.1.0list expression
list1.jpg (23.9 KiB)
list2.jpg (56.6 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.

Amy M3 avatar image
0 Likes"
Amy M3 answered

Ok, got the .fsl loaded and it worked until i made it dynamic(then says puller required) but I did get my if statement working based on your example..i was missing the "return"..still trying to learn the syntax of everything! Thanks for your help. Here is what I ended up using-

if (value.RecipeIndex==value.SourceSwingBinRecipeIndex)

return value.as(FlowTank).content +value.SourceSwingBinObject.as(FlowTank).content*value.SourceBinShareFactor+value.WIP_lbs;

else

return value.as(FlowTank).content +value.WIP_lbs;

5 |100000

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

Amy M3 avatar image
0 Likes"
Amy M3 answered Jason Lightfoot commented
I'll try it, how do I get the .fsl into my model?
· 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.

Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·

File-> Open User Libraries

0 Likes 0 ·
Amy M3 avatar image
0 Likes"
Amy M3 answered Jason Lightfoot edited

Thought I replied earlier, i could get a value from another column but never did get the if statement to work in a list.

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

Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·

The value you want to use has to be returned from the code so it will be something like:

if (getFieldValue("RecipeIndex",c,value,puller,entry,pushTime)==getFieldValue("SourceSwingBinRecipeIndex",c,value,puller, entry, pushTime))         
     return getFieldValue("SourceSwingBin_lbs",c,value,puller, entry, pushTime);
else
    return 0;
0 Likes 0 ·
Amy M3 avatar image
0 Likes"
Amy M3 answered

I came up with a workaround, i put a label on my objects pushing to list(bins) to check for a match with their source bin(returns 1 or 0). Now I can multiply that in my list so only includes inventory if i find a match. I will have to figure out when to update the label whenever inventory changes. Would love to be able to create conditional columns in lists using expressions.



5 |100000

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

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Amy M3 commented

The question is really about accessing the fields in a list from other fields and is possible but not strictly supported. I'll add a request to the dev list to consider adding this capability.

In the attached model is a user command getFieldValue which may meet your immediate needs.


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

Amy M3 avatar image Amy M3 commented ·

@jason.lightfoot any chance you have that example in version 21.0.3? im using floworks and trying to hit a deadline so afraid to upgrade right now as i typically have had issues.

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Amy M3 commented ·

Attached are 21.0 and a .fsl library which will put the command into your model when you load it.

21.0_ListExpressionReferencesAnotherField.fsl

getFieldValue.fsl

0 Likes 0 ·
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

Any list field is a result of an attribute of the value. You have in any field access to the value. Now you compute the attribute fields of “recipeIndex“ and „sourceSwingl“ by the value field and set conditionally the expression. If those fields aren’t labels or results of expressions than you can get access to them by a Table.query over the global list itself.

5 |100000

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

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.