Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
Hello Everyone,
I'm trying to make a integer field that uses a computation value. The definition would be something similar to an if statement in java.
For example, if "Field1" == "yes" AND "Field2" == "yes", i want the integer to be 2.
So far I've tried something like ("Field1" == "YES") AND ("Field2" == "YES") ? 2
and also
(
(
("field1" == "yes") and
(
("field2" == "one") or
("field2" == "two") or
("field2" == "three") or
("field2" == "four")
)
)
? 2
Both have given me syntax error. I'm not completely sure if I'm going towards the right path, as i can't find any documentations on statements like these.
If any of you guys can provide some insight, or even what programming language ptc uses, it would be much appreciated.
Hello,
I don't think the programming language (java) is relevant, calculated field are their own thing implemented by PTC.
We may need more details about your specific use case and error message. In the meantime, here are two examples I have, that both calculate an integer field:
( Discipline == "Systems" ? 100 : 0 ) + ( State = "Submission" ? 11 : ( State = "Construction" OR State = "Construction Review" ? 21 : 0 ) )
and
IsEmpty( Severity < 4 ? ( Severity * 0.1 ) : ( ( Severity * 2 - 3 + Floor( Severity / 6 ) ) * 0.1 ) , 1.0 )
I think they're pretty close to what you're trying to do syntax-wise. Note that field names without spaces don't need double-quotes but I don't think that would trigger an error.
From your examples, you may be missing the "else" value which is mandatory, that's the one after the colon.
Hi @KD_9967107 ,
May be you can refer this:-
(
(
(
(Occurrence == "Improbable (0)") and
(
(Severity == "Negligible (0)") or
(Severity == "Minor (1)") or
(Severity == "Serious (2)")
)
) or
(
(Occurrence == "Remote (1)") and
(
(Severity == "Negligible (0)") or
(Severity == "Minor (1)")
)
) or
(
(Occurrence == "Occasional (2)") and
(
(Severity == "Negligible (0)")
)
)
)
? 2
: (
(
(
(
(Occurrence == "Improbable (0)") and
(
(Severity == "Critical (3)") or
(Severity == "Catastrophic (4)")
)
) or
(
(Occurrence == "Remote (1)") and
(
(Severity == "Serious (2)") or
(Severity == "Critical (3)")
)
) or
(
(Occurrence == "Occasional (2)") and
(
(Severity == "Minor (1)") or
(Severity == "Serious (2)")
)
) or
(
(Occurrence == "Probable (3)") and
(
(Severity == "Negligible (0)") or
(Severity == "Minor (1)")
)
) or
(
(Occurrence == "Frequent (4)") and
(
(Severity == "Negligible (0)")
)
)
)
? true : false
)
? 1
: (
(
(
(
(Occurrence == "Remote (1)") and
(
(Severity == "Catastrophic (4)")
)
) or
(
(Occurrence == "Occasional (2)") and
(
(Severity == "Critical (3)") or
(Severity == "Catastrophic (4)")
)
) or
(
(Occurrence == "Probable (3)") and
(
(Severity == "Serious (2)") or
(Severity == "Critical (3)") or
(Severity == "Catastrophic (4)")
)
) or
(
(Occurrence == "Frequent (4)") and
(
(Severity == "Minor (1)") or
(Severity == "Serious (2)") or
(Severity == "Critical (3)") or
(Severity == "Catastrophic (4)")
)
)
)
? true : false
)
? 0
: 99
)
)
)