Skip to main content
Known Participant
Jun 9, 2023 7:17 AM UTC
Solved

Convert List of Text String to List

I have a local variable which is receiving BacthPayloadInput Response from process model

local!updatedPurchasers_at: index(
ri!EF_GeneralUpdatePayload_cdt.RequestJson,
wherecontains(
tostring("PowerPurchasers"),
cast(103, index(ri!EF_GeneralUpdatePayload_cdt,"RequestEndpoint",{}))
),
null
),

when i output the values it contains in expression rule it gives me output like this:

I want to extract the only "KeyPowerPurchasers" out of it which i am not able to do so.

I have been trying to get it in following these two methods but both are having problem:

first one:

local!purchaserKeys_int:reject(
fn!isnull,
{
if(
a!isNullOrEmpty(local!updatedPurchasers_at),
null,
cast(101, index(local!updatedPurchasers_at, "KeyPowerPurchasers", {}))
)
}
),

it gives empty array {}

2nd one:

  local!purchaserKeys_int:reject(
fn!isnull,
{
if(
a!isNullOrEmpty(local!updatedPurchasers_at),
null,
cast(101,a!fromJson(local!updatedPurchasers_at).KeyPowerPurchasers)
)
}
),

this gives 

Expression evaluation error at function a!fromJson : The jsonText parameter was not valid JSON.

can anyone please guide how can i get the list of KeyPowerPurchasers out of it only?

harshitb6843
Brainy
Jun 9, 2023 7:19 AM UTC

a!forEach(
  items: local!list,
  expression: extract(
    fv!item,"KeyPowerPurchasers:",","
  )
)

Save your output in a variable and pass that in place of local!list

8 replies

harshitb6843
Brainy
Jun 9, 2023 7:19 AM UTC

a!forEach(
  items: local!list,
  expression: extract(
    fv!item,"KeyPowerPurchasers:",","
  )
)

Save your output in a variable and pass that in place of local!list

Known Participant
Jun 9, 2023 7:25 AM UTC

is it possible to map it into single list?

harshitb6843
Brainy
Jun 9, 2023 7:28 AM UTC

How do you want your output to look like?

sunilc6392
Participating Frequently
Jun 9, 2023 7:28 AM UTC

mikes0011
Brainy
Jun 9, 2023 2:32 PM UTC

Do you have any control over how the data is formatted before being passed out from the process model?  It'd save you a lot of hassle in terms of parsing if you just wrap the data into a JSON string, instead of trying to do your own ad-hoc parsing.

The Expression Guru
Inspiring
Jun 9, 2023 5:28 PM UTC

You can also utilize the keval() function:

a!localVariables(
  local!list: {
    "[KeyPowerPurchaser:-2147483254,ExpectedPowerPurchased: 123]",
    "[KeyPowerPurchaser:-2147483253,ExpectedPowerPurchased: 456]"
  },
  local!result: a!forEach(
    items: local!list,
    expression: keyval(
      local!list[fv!index],  /* text  */
      "KeyPowerPurchaser",   /* keys  */
      ":",                   /* separtors  */
      ","                    /* delimiters  */
    )
  ),
  a!flatten(local!result)
)


The result will be: