Web API to processParameter

Hello all,

I want to send the following body from Web API to Process Model, I need to change the format as shown below, 

Web API Code:

{
"references": {
"ABC": "111",
"DEF": "222",
"GHI": "333",
"JKL": "444",
"other": {"MNO-555", "XYZ-123", "PQR-666"}
}
}

Change this to the following format:

[ref_text=111, refSource_text=ABC],
[ref_text=222, refSource_text=DEF],
[ref_text=333, refSource_text=GHI],
[ref_text=444, refSource_text=JKL],
[ref_text=555, refSource_text=MNO],
[ref_text=123, refSource_text=XYZ],
[ref_text=666, refSource_text=PQR]

Appreciate if anyone can help me in resolving it, thanks in advance.

  Discussion posts and replies are publicly visible

Parents
  • Getting the values form the "other" segment of the data is pretty straightforward:

    a!forEach(
        items: local!myData.references.other,
        expression: 
          with(
            local!nameValues: fn!split(fv!item,"-"),
            {
              ref_text: local!nameValues[2],
              refSource_text: local!nameValues[1]
            }
          )

    The issue is with the first set of data in the array in that you would need to set up a loop to process the items but unless they're always going to have the same 'label' in their label:value pair we can't extract the label and value from the individual item. Unless you can tell me you know in advance what the list of dictionary labels would be for any given instance of the data?

  • Thanks Stewart. Yes, the label values are going to be same in the first set. And, I need to eventually store these values in a CDT.

  • +1
    Appian Employee
    in reply to sunilc

    If you are certain that the labels for the first four items are always the same, then you can index them directly to reassign them (adding on top of what Stewart already suggested). For example, this should work:

    a!localVariables(
      local!data: {
        "references": {
          "ABC": "111",
          "DEF": "222",
          "GHI": "333",
          "JKL": "444",
          "other": {"MNO-555", "XYZ-123", "PQR-666"}
        }
      },
      {
        {ref_text: local!data.references.ABC, refSource_text: "ABC"},
        {ref_text: local!data.references.DEF, refSource_text: "DEF"},
        {ref_text: local!data.references.GHI, refSource_text: "GHI"},
        {ref_text: local!data.references.JKL, refSource_text: "JKL"},
        a!forEach(
          items: local!data.references.other,
          expression: a!localVariables(
            local!nameValues: fn!split(fv!item,"-"),
            {
              ref_text: local!nameValues[2],
              refSource_text: local!nameValues[1]
            }
          )
        )
      }
    )

    In general though, I'd recommend looking at the API to see if it can be refactored to support the information in a clearer way. This is not specific to Appian; most tools expect data to be returned in a set of key value pairs where the key is consistent across a list of values. It will be much easier to deal with the data in Appian if it uses a more consistent format.

Reply
  • +1
    Appian Employee
    in reply to sunilc

    If you are certain that the labels for the first four items are always the same, then you can index them directly to reassign them (adding on top of what Stewart already suggested). For example, this should work:

    a!localVariables(
      local!data: {
        "references": {
          "ABC": "111",
          "DEF": "222",
          "GHI": "333",
          "JKL": "444",
          "other": {"MNO-555", "XYZ-123", "PQR-666"}
        }
      },
      {
        {ref_text: local!data.references.ABC, refSource_text: "ABC"},
        {ref_text: local!data.references.DEF, refSource_text: "DEF"},
        {ref_text: local!data.references.GHI, refSource_text: "GHI"},
        {ref_text: local!data.references.JKL, refSource_text: "JKL"},
        a!forEach(
          items: local!data.references.other,
          expression: a!localVariables(
            local!nameValues: fn!split(fv!item,"-"),
            {
              ref_text: local!nameValues[2],
              refSource_text: local!nameValues[1]
            }
          )
        )
      }
    )

    In general though, I'd recommend looking at the API to see if it can be refactored to support the information in a clearer way. This is not specific to Appian; most tools expect data to be returned in a set of key value pairs where the key is consistent across a list of values. It will be much easier to deal with the data in Appian if it uses a more consistent format.

Children