How to edit nested objects in Appian Script task in process

Certified Associate Developer

Hi,

I have a data like 

{
  'type!{urn:com:appian:types:CB}CB_Builder_Checklist_And_Items'(
    'checklist': 'type!{urn:com:appian:types:CB}CB_Builder_Checklist'(
      'id': 32,
      'name': "Test",
      'description': "Test",
      'owner': "",
      'use_group_additional_owners': false
    ),
    'checklistItems': {
      'type!{urn:com:appian:types:CB}CB_Builder_C_Item'(
        'id': 47,
        'name': "Test1",
        'item_type_id': 6,
        'isInterval': false,
        'validate_answer': false,
        'owner': "",
        'use_group_additional_owners': false,
        'choice_multiple': false,
        'mandatory_comment_fail': false,
        'description': "Test"
      )
    }
  ),
  'type!{urn:com:appian:types:CB}CB_Builder_Checklist_And_Items'(
    'checklist': 'type!{urn:com:appian:types:CB}CB_Builder_Checklist'(
      'id': 47,
      'name': "Test",
      'description': "Test",
      'owner': "",
      'use_group_additional_owners': false
    ),
    'checklistItems': {
      'type!{urn:com:appian:types:CB}CB_Builder_C_Item'(
        'id': 72,
        'name': "Test1",
        'item_type_id': 8,
        'isInterval': false,
        'validate_answer': false,
        'owner': "",
        'use_group_additional_owners': false,
        'choice_multiple': false,
        'mandatory_comment_fail': false,
        'description': "Test"
      )
    }
  )
}

now I have to assign all the ids to null value in a script task in process model. How to do that?
I have tried:

a!forEach(
  items: pv!ChecklistsAndItems,
  expression: {
    fv!item.checkist.id:1,
    a!update(data:fv!item.checklistItems, index:"id", value: 1)
  }
)

It not worked for me. How to achieve this?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    It not worked for me

    ??? What output do you observe?

    ... a few moments later ... a tiny working example

    a!localVariables(
      local!data: {
        {
          id: 1,
          items: {
            {id: 2},
            {id: 3},
          }
        },
        {
          id: 4,
          items: {
            {id: 5},
            {id: 6},
          }
        },
      },
      a!forEach(
        items: local!data,
        expression: a!update(
          /* Pass the updated data with a new ID */
          data: a!update(
            data: fv!item,
            index: "id",
            value: fv!index + 5
          ),
          /* Then the econd update comes here */
          index: "items",
          value: a!forEach(
            items: fv!item.items,
            expression: a!update(
              data: fv!item,
              index: "id",
              value: fv!index + 6
            )
          )
        )
      )
    )

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    a!localVariables(
      local!data: {
        {
          subdata: {id:1},
          subdataitems: {
            {id: 2},
            {id: 3},
          }
        },
        {
          subdata: {id:1},
          subdataitems: {
            {id: 5},
            {id: 6},
          }
        },
      },
    )


    Now I want output like this

    {
        {
          subdata: {id:null},
          subdataitems: {
            {id: null},
            {id: null},
          }
        },
        {
          subdata: {id:null},
          subdataitems: {
            {id: null},
            {id: null},
          }
        },
      }


    Now how do I achieve this?

    Thanks

  • 0
    Certified Senior Developer
    in reply to Sowvik Roy

      Please try the below code.

    a!localVariables(
      local!testData: {
        'type!{urn:com:appian:types:SS}SS_TEST'(
          testId: 1,
          fieldOne: "testValue1",
          fieldTwo: "testValue2",
          accountHolderDetails: 'type!{urn:com:appian:types:SS}SS_Account_Holder'(
            id: 4,
            firstName: "John",
            email: "sample@test.com"
          ),
          creditCardDetails: {
            'type!{urn:com:appian:types:SS}SS_Credit_Card'(
              creditCardId: 20,
              cardHolderId: 1323,
              lastFourDigits: "8962",
              creditLimit: "100000"
            ),
            'type!{urn:com:appian:types:SS}SS_Credit_Card'(
              creditCardId: 28,
              cardHolderId: 1323,
              lastFourDigits: "8972",
              creditLimit: "100000"
            )
          }
        ),
        'type!{urn:com:appian:types:SS}SS_TEST'(
          testId: 2,
          fieldOne: "testValue1",
          fieldTwo: "testValue2",
          accountHolderDetails: 'type!{urn:com:appian:types:SS}SS_Account_Holder'(
            id: 22,
            firstName: "Daniel",
            email: "sample23@test.com"
          ),
          creditCardDetails: {
            'type!{urn:com:appian:types:SS}SS_Credit_Card'(
              creditCardId: 100,
              cardHolderId: 1800,
              lastFourDigits: "8962",
              creditLimit: "100000"
            ),
            'type!{urn:com:appian:types:SS}SS_Credit_Card'(
              creditCardId: 200,
              cardHolderId: 1800,
              lastFourDigits: "8972",
              creditLimit: "100000"
            )
          }
        )
      },
      a!forEach(
        items: local!testData,
        expression: a!localVariables(
          local!accountHolderDetailsUpdated: a!update(
            data: fv!item.accountHolderDetails,
            index: "id",
            value: null
          ),
          local!creditCardUpdated: a!update(
            data: fv!item.creditCardDetails,
            index: "creditCardId",
            value: null
          ),
          'type!{urn:com:appian:types:SS}SS_TEST'(
            testId: fv!item.testId,
            fieldOne: fv!item.fieldOne,
            fieldTwo: fv!item.fieldTwo,
            accountHolderDetails: local!accountHolderDetailsUpdated,
            creditCardDetails: local!creditCardUpdated
          )
        )
      )
    )

Reply
  • 0
    Certified Senior Developer
    in reply to Sowvik Roy

      Please try the below code.

    a!localVariables(
      local!testData: {
        'type!{urn:com:appian:types:SS}SS_TEST'(
          testId: 1,
          fieldOne: "testValue1",
          fieldTwo: "testValue2",
          accountHolderDetails: 'type!{urn:com:appian:types:SS}SS_Account_Holder'(
            id: 4,
            firstName: "John",
            email: "sample@test.com"
          ),
          creditCardDetails: {
            'type!{urn:com:appian:types:SS}SS_Credit_Card'(
              creditCardId: 20,
              cardHolderId: 1323,
              lastFourDigits: "8962",
              creditLimit: "100000"
            ),
            'type!{urn:com:appian:types:SS}SS_Credit_Card'(
              creditCardId: 28,
              cardHolderId: 1323,
              lastFourDigits: "8972",
              creditLimit: "100000"
            )
          }
        ),
        'type!{urn:com:appian:types:SS}SS_TEST'(
          testId: 2,
          fieldOne: "testValue1",
          fieldTwo: "testValue2",
          accountHolderDetails: 'type!{urn:com:appian:types:SS}SS_Account_Holder'(
            id: 22,
            firstName: "Daniel",
            email: "sample23@test.com"
          ),
          creditCardDetails: {
            'type!{urn:com:appian:types:SS}SS_Credit_Card'(
              creditCardId: 100,
              cardHolderId: 1800,
              lastFourDigits: "8962",
              creditLimit: "100000"
            ),
            'type!{urn:com:appian:types:SS}SS_Credit_Card'(
              creditCardId: 200,
              cardHolderId: 1800,
              lastFourDigits: "8972",
              creditLimit: "100000"
            )
          }
        )
      },
      a!forEach(
        items: local!testData,
        expression: a!localVariables(
          local!accountHolderDetailsUpdated: a!update(
            data: fv!item.accountHolderDetails,
            index: "id",
            value: null
          ),
          local!creditCardUpdated: a!update(
            data: fv!item.creditCardDetails,
            index: "creditCardId",
            value: null
          ),
          'type!{urn:com:appian:types:SS}SS_TEST'(
            testId: fv!item.testId,
            fieldOne: fv!item.fieldOne,
            fieldTwo: fv!item.fieldTwo,
            accountHolderDetails: local!accountHolderDetailsUpdated,
            creditCardDetails: local!creditCardUpdated
          )
        )
      )
    )

Children
No Data