Having multiple saves in braces

Certified Senior Developer

Hello,

Is there any reason that Appian would only execute the first a!save inside a bracket, and not the rest of it? The code goes into the second part of the if statement, and only runs whichever is the first function in the braces. If I switch the order of the 2, it still only runs the first one. 

Attached is my code. Thank you for your help. 

if(
index(
local!existingEvaluationPlanSnapshot,
"evaluation_id_fk",
null
) = local!relevantEvaluation.id_pk,
a!save(
ri!evaluationAction,
local!existingEvaluationPlanSnapshot
),
{
a!save(
ri!evaluationActionToDelete,
local!existingEvaluationPlanSnapshot
),
a!save(
ri!evaluationAction,
'type!{urn:com:appian:types}evaluationActions'(
evaluation_id_fk: local!relevantEvaluation.id_pk,
action_plan_id_fk: ri!actionPlan.id_pk,
created_by: loggedInUser(),
created_on: now()
)
)
}
),

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I've gotten multiple saves in an array to work many times in the past.  Idon't see anything overtly incorrect in the code you've posted, though I feel like there could be a bit more context provided - is this happening in a button click, a field save, etc?  If you could post another code sample with a bit of expanded form context, it might help us spot anything incorrect.  I appreciate that you already troubleshot by switching the ordering, that's informative, though I'm still not sure what the issue could be.

    As an aside, it'll make your code easier to post and read if you use the "Insert --> Insert Code" functionality here to generate a code box that you can then paste your code into; doing it this way generally maintains indentation (assuming you're pasting in code that's indented properly) and also limits how much space the code "wastes" on the post in general (the box it provides is scrollable which is nice).  Just FYI Slight smile

Reply
  • 0
    Certified Lead Developer

    I've gotten multiple saves in an array to work many times in the past.  Idon't see anything overtly incorrect in the code you've posted, though I feel like there could be a bit more context provided - is this happening in a button click, a field save, etc?  If you could post another code sample with a bit of expanded form context, it might help us spot anything incorrect.  I appreciate that you already troubleshot by switching the ordering, that's informative, though I'm still not sure what the issue could be.

    As an aside, it'll make your code easier to post and read if you use the "Insert --> Insert Code" functionality here to generate a code box that you can then paste your code into; doing it this way generally maintains indentation (assuming you're pasting in code that's indented properly) and also limits how much space the code "wastes" on the post in general (the box it provides is scrollable which is nice).  Just FYI Slight smile

Children
  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

     a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Save" & if(
                ri!actionPlan.status_id_fk = cons!PIX_REF_TYPE_ACTION_PLAN_STATUS_DRAFT,
                " Draft",
                ""
              ),
              confirmHeader: "Save Action Plan?",
              confirmMessage: if(
                ri!actionPlan.status_id_fk = cons!PIX_REF_TYPE_ACTION_PLAN_STATUS_DRAFT,
                " Action plan will be saved as a draft",
                " Changes will be saved"
              ),
              saveInto: {
                /*Saving evaluation action plan*/
                if(
                  local!isSavingEvaluation,
                  if(
                    rule!APN_isBlank(
                      index(
                        local!existingEvaluationPlanSnapshot,
                        "id_pk",
                        null
                      )
                    ),
                    a!save(
                      ri!evaluationAction,
                      'type!{urn:com:appian:types:PIX}PIX_evaluationActions'(
                        evaluation_id_fk: local!relevantEvaluation.id_pk,
                        action_plan_id_fk: ri!actionPlan.id_pk,
                        created_by: loggedInUser(),
                        created_on: now()
                      )
                    ),
                    if(
                      index(
                        local!existingEvaluationPlanSnapshot,
                        "evaluation_id_fk",
                        null
                      ) = local!relevantEvaluation.id_pk,
                      a!save(
                        ri!evaluationAction,
                        local!existingEvaluationPlanSnapshot
                      ),
                      {
                        a!save(
                          ri!evaluationActionToDelete,
                          local!existingEvaluationPlanSnapshot
                        ),
                        a!save(
                          ri!evaluationAction,
                          'type!{urn:com:appian:types}evaluationActions'(
                            evaluation_id_fk: local!relevantEvaluation.id_pk,
                            action_plan_id_fk: ri!actionPlan.id_pk,
                            created_by: loggedInUser(),
                            created_on: now()
                          )
                        )
                      }
                    ),
                  ),
                  {}
                )
                }
                ),
             a!buttonWidget(...)
        }
    )

    Here is more of the code. To give more context, this save function is in the saveInto for the a save button. Please let me know if this amount of context is enough, or if there is anything else that may be helpful. Is there anything that could potentially be the cause of it? 

  • 0
    Certified Lead Developer
    in reply to KC

    Thanks for the extended snippet.  I don't find any obvious errors in it - though I don't know if you need to manually typecast in your a!save statements into the evaluationActions type; if the Rule Input is the defined as the correct CDT already, then typecasting will automatically occur upon save, and you could simply pass a dictionary with the field(s) you want.

    So, I was able to copy this over to a blank interface in one of my sandbox environments and define some of the local variables and rule inputs (making them all one step more generic), and when I try the button press, I can verify that both saves in the final list-of-save are working for me.  So your problem could be something more subtle, I suppose - maybe there's an issue being caused by the type! operators (though if so I haven't seen it before).  Here's the revised code I used, in a blank interface with text rule inputs (in my case) created to handle the 3 rule input variables:

    a!localVariables(
      local!isSavingEvaluation: a!refreshVariable(
        value: true(),
        refreshAlways: true()
      ),
      local!relevantEvaluation: {
        id_pk: 123
      },
      local!existingEvaluationPlanSnapshot: a!refreshVariable(
        value: {
          id_pk: 234,
          evaluation_id_fk: /* comment out only one of the following: */
            123
            /*321*/
        },
        refreshAlways: true()
      ),
      a!buttonLayout(
        primaryButtons: {
          a!buttonWidget(
            label: "Save",
            confirmHeader: "Save Action Plan?",
            confirmMessage: "Changes will be SaveD",
            saveInto: {
              /*Saving evaluation action plan*/
              if(
                local!isSavingEvaluation,
                if(
                  rule!APN_isBlank(
                    property( local!existingEvaluationPlanSnapshot, "id_pk", null )
                  ),
                  a!save(
                    ri!evaluationAction,
                    {
                      name: "new",
                      evaluation_id_fk: local!relevantEvaluation.id_pk,
                      action_plan_id_fk: 345,
                      created_by: loggedInUser(),
                      created_on: now()
                    }
                  ),
                  if(
                    property( local!existingEvaluationPlanSnapshot, "evaluation_id_fk", null ) = local!relevantEvaluation.id_pk,
                    a!save(
                      ri!evaluationAction,
                      local!existingEvaluationPlanSnapshot
                    ),
                    {
                      a!save(
                        ri!evaluationActionToDelete,
                        local!existingEvaluationPlanSnapshot
                      ),
                      a!save(
                        ri!evaluationAction,
                        /*'type!{urn:com:appian:types}evaluationActions'(*/
                        {
                          name: "revised",
                          evaluation_id_fk: local!relevantEvaluation.id_pk,
                          action_plan_id_fk: 456,
                          created_by: loggedInUser(),
                          created_on: now()
                        /*)*/
                        }
                      )
                    }
                  ),
                ),
                {}
              )
            }
          ),
          /*a!buttonWidget(...)*/
        }
      )
    )

    Here is my result when executing the button click:

  • Our posts crossed Mike :)  I'm assuming if you turn your locals into a List with an extra {}, you can replicate the issue.  Type vs List of Type appears to be the issue, but it does seem buggy since the logic executes within if() but stops after the first a!save.

  • 0
    Certified Lead Developer
    in reply to Chris

    That might be - people need to remember that if() statements can do funny things when the results are lists, since if() itself can handle a list of input parameters of any length (as long as that length is an odd number).

  • Yes, definitely.  To add here from my test code, if we change to:

    local!data: {{version: 3},{version: 3}},

    and the if() expression to:

    tointeger(local!data.version)>{2,2},

    ..Then the first TWO saves occur.  So, for a list type in the if() expression, the amount of a!saves fired from that list will match how many items are in the if() expression list.  List definitely can be fun(ny), but not a "bug" I guess!  Also allows for interesting designs I haven't really used before.

    with(
    local!data: {
    {item: 1},
    {item: 2},
    {item: 3},
    {item: 4},
    {item: 5}
    },

    if(
    tointeger(local!data.item)>makerange(count(local!data.item),3),
    makerange(count(local!data.item),true),
    makerange(count(local!data.item),false)
    )
    )