Update fields of another record with multiple conditions in a process

Hi! I have made a process in which my Invoice Lines (Record 1) are set with the status "Billed" in the end, after passing multiple logics.

Now, I would like to query the Purchase Order Lines (Record 2) from my process model and set their status to "Billed" too. In this case, I have to apply the following conditions:

1) The Purchase Order ID is the same as the used in my process 

2) The materials of the Order Lines are the same as the ones created in the process

I have been trying with the query database smart service (update-set-where) but it gives me problems when trying to filter by a more than one string (materials)

How can I afford this "update" in my process? Which smart services do you recommend me to use?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    For these scenarios, I create an expression rule which takes the invoice id as a rule input, then queries the items and modifies them in a foreach using a!update().

    Then I call that expression in a script task, storing the results in a PV. Then I write the items using a write records node.

  • Alright, I understand the idea, but I´m not sure how to take the invoice id as a rule input in my expression. Could I ask for an example with code in order to understand the structure? I have doubts to make the expression rule you mention, and how to add the a!foreach inside the a!queryRecordType

    The a!foreach structure should be something like this:

    a!forEach(
      items: ['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido'],
      expression: a!update(
        ['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido'],
        "facturada",
        true
      )
    )

    And now this is the code I´m trying (it gives me an error and I dont know the idPedido as a rule input):

    a!forEach(
      items: 
      a!queryRecordType(
        recordType: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido',
        fields: {
          'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{caf81eeb-f499-4adc-b078-f2692f6e38b2}ConcatPedidoMaterial', 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fab0f2c1-705c-4acb-8d49-76f45778795f}facturada'
        },
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100)
      ),
      expression: a!update(
        'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido',
        "facturada",
        true
      )
      ).data

    Any help would for the rest of the expression would be useful, thanks!

  • I have just put my code with the "insert code"; it was my fault, sorry!

  • 0
    Certified Lead Developer
    in reply to carlosp5114

    What do you mean?!? This is covered in the most basic Appian trainings. I described the three steps already:

    - Create invoice id as a rule input

    - then queries the items

    - modifies them in a foreach using a!update().

    a!forEach(
      items: a!queryRecordType(
        recordType: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido',
        fields: {
          'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{caf81eeb-f499-4adc-b078-f2692f6e38b2}ConcatPedidoMaterial', 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fab0f2c1-705c-4acb-8d49-76f45778795f}facturada'
        },
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100),
        filters: {
          a!queryFilter(... filter for id from rule input...)
        }
      ).data,
      expression: a!update(
        fv!item,
        "facturada",
        true
      )
      )

  • Thanks Stefan. Of course my rule input (idPedido) has been created in the process. And if do the expression directly in the process, I can reference that value ("Borrar3"). But in the query editor, I´m just testing putting the value manually. I have adapted the code but my query result shows me that the update is not working:

    * "facturada" should appear as true

    What is wrong with my code this time?

    a!forEach(
      items: a!queryRecordType(
        recordType: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido',
        fields: {
          'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{caf81eeb-f499-4adc-b078-f2692f6e38b2}ConcatPedidoMaterial', 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fab0f2c1-705c-4acb-8d49-76f45778795f}facturada'
        },
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100),
        filters: {
          a!queryFilter(
            field: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido',
            operator: "=",
            value: "Borrar3"
          )
        }
      ),
      expression: a!update(
        fv!item,
        "facturada",
        true
      )
    ).data

  • 0
    Certified Lead Developer
    in reply to carlosp5114

    Rule inputs!!!! https://docs.appian.com/suite/help/23.3/Expression_Rules.html#add-rule-inputs

    The main issue here is, that you added the ".data" at the end of the foreach() instead of the end of a!queryRecordType().

  • Alright, I changed the data and indexed it with the uniqueId (concatPedMat). I tested it without the update and it works correctly, but there is a problem with the update, in the fv!item

    ("A list, map, dictionary, CDT, or Record is expected as the first parameter. Received Text")

    a!forEach(
      items: index(a!queryRecordType(
        recordType: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido',
        fields: {
          'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{caf81eeb-f499-4adc-b078-f2692f6e38b2}ConcatPedidoMaterial', 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fab0f2c1-705c-4acb-8d49-76f45778795f}facturada'
        },
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100),
        filters: {
          a!queryFilter(
            field: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido',
            operator: "=",
            value: "Borrar3"
          )
        }
      ).data,
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{caf81eeb-f499-4adc-b078-f2692f6e38b2}ConcatPedidoMaterial',
      {}
      ),
      expression: a!update(
        fv!item,
        "facturada",
        true
      )
    )

  • 0
    Certified Lead Developer
    in reply to carlosp5114

    I do not understand what the index() would do to solve the problem. You need to pass a list of record to the "items" parameter. a!queryRecordType returns a datasubset. Adding ".data" then extracts the list of record from that datasubset. All of this is covered in the Appian trainings, tutorials and documentation.

    a!forEach(
      items: a!queryRecordType(
        recordType: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido',
        fields: {
          'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{caf81eeb-f499-4adc-b078-f2692f6e38b2}ConcatPedidoMaterial', 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fab0f2c1-705c-4acb-8d49-76f45778795f}facturada'
        },
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100),
        filters: {
          a!queryFilter(
            field: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido',
            operator: "=",
            value: "Borrar3"
          )
        }
      ).data,
      expression: a!update(
        fv!item,
        "facturada",
        true
      )
    )

Reply
  • 0
    Certified Lead Developer
    in reply to carlosp5114

    I do not understand what the index() would do to solve the problem. You need to pass a list of record to the "items" parameter. a!queryRecordType returns a datasubset. Adding ".data" then extracts the list of record from that datasubset. All of this is covered in the Appian trainings, tutorials and documentation.

    a!forEach(
      items: a!queryRecordType(
        recordType: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido',
        fields: {
          'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{caf81eeb-f499-4adc-b078-f2692f6e38b2}ConcatPedidoMaterial', 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fab0f2c1-705c-4acb-8d49-76f45778795f}facturada'
        },
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100),
        filters: {
          a!queryFilter(
            field: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido',
            operator: "=",
            value: "Borrar3"
          )
        }
      ).data,
      expression: a!update(
        fv!item,
        "facturada",
        true
      )
    )

Children
No Data