Skip to main content
November 4, 2024
Question

How to edit nested objects in Appian Script task in process

  • November 4, 2024
  • 4 replies
  • 0 views

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?

4 replies

stefanhelzle0001
November 4, 2024
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
        )
      )
    )
  )
)

November 5, 2024

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

shanmathip7466
November 5, 2024

[mention:badc3eb7553340be80ed947b482eb441:e9ed411860ed4f2ba0265705b8793d05]  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
      )
    )
  )
)