Clarity

  • 1.  Calculated date attribute with conditions

    Posted Jan 13, 2017 07:10 AM

    If the calculated date attribute has the syntax

    Function Syntax
    DateAdd(date attribute, unit, number)

     

    that does not sound like it is possible to have conditions for the number of the units to be used.

     

    Or is there a way to use different values for the number of units depending on the value of another field?

     

    If not, would that be possible with a process?



  • 2.  Re: Calculated date attribute with conditions

    Posted Jan 13, 2017 10:22 AM

    How does your 'another field' look like? 



  • 3.  Re: Calculated date attribute with conditions

    Posted Jan 13, 2017 10:30 AM

    Don't you just need to generate a relevant Sub-expression to include in the calculation as Argument 3 ?

    (or Attribute Name (ID) if its just a simple attribute)



  • 4.  Re: Calculated date attribute with conditions

    Posted Jan 13, 2017 05:28 PM

    Thanks again for the education.

    With DateAdd the argument 3 must numeric.

    So in addition to a constant number a numeric field is OK and so is a lookup where the ID is numeric.

     

    If that is to be conditional it is getting trickier.

    If the argument 3 is going to be different than the value of the referenced field it has to be a lookup field.

    That has to be constructed so that the ID is equals to the value required while the display value is what is really wanted.

     

    Eg. say the calculated date is target date depending on the value of the class attribute for the instance.

    If the class is New Install then the target date should be 50 days more than the created date.

    If the class is Update then the target date should be 20 days more.

    That works if the class is using a lookup field where value New Install had ID 50 and Update has ID 20.

    If not eg it is not a lookup then that would not work and a more complex expressions is required.

    Is that possible?

    Is it possible to use if or case statements.



  • 5.  Re: Calculated date attribute with conditions

    Posted Jan 16, 2017 03:59 AM

    "Is it possible to use if or case statements" - no, it is not. Can only use "expressions" - which are other calculated attribute expressions.

     

    To get "logic" into the calculated field we have to be "imaginative" - I think that you have the right idea with making the "case" statement part of the lookup definition, but if thats not possible then you are stuck with the logic 

    that you can build in the calculated attribute expression (i.e. Absolute / Add / Average / DateDiff / Divide / Max / Min / Multiply / Percentage / Power / Round / Sqrt / Subtract / Sum / Trunc), which is limited.



  • 6.  Re: Calculated date attribute with conditions
    Best Answer

    Posted Jan 16, 2017 12:29 PM

    Thanks. Yes, does not seem to be possible if you look at the list of expressions/functions

    (eg at https://docops.ca.com/ca-ppm/15-1/en/administration/reference/ca-ppm-studio-development/ca-ppm-studio-objects-and-attrib… )

    After that the only way to do that I see is to use the id of a lookup field. That makes any modifications cumbersome as the ID of a lookup cannot be changed and cannot be used at all if the ID is not numeric.

     

    Other options not using a calculated field could be

     

    Auxiliary field which would have the value of argument 3. That would give the argument3 of AddDate directly, but the same problem is there: How to get different values based on the value of another field.

     

    GEL process to write the value. Direct db write is not supported, but sometimes done for custom attributes. The attribute in question beeing a project attribute the supported way of writing the value with XOG is a pain, because this is the project object with a number of custom attributes.

    There could be ways of circumventing some of that by using a custom object and a flag field in it.

     

    However, the most attractive seems to be just to add that field to another process which is already there and writing project custom attribute with XOG soon after creation. The logic can be added to the GEL script.