Skip to main content
December 28, 2023
Solved

Indexing the values is returned as an array value"[]", but it is a single value

  • December 28, 2023
  • 4 replies
  • 0 views

I am trying to return some values in a web API of mine where I call an expression rule that maps the vales that are wanted. The thin is I used index() function to cast the values like this 

childId: rule!A_QE(index(fv!item, "id", null()))['recordType!{record}Record.fields.{record}.childId'],

where the item is going through an iterative loop to fetch each list.

in the web API it is getting returned as: 

"childId" : [ 777 ],

which i do not want it in this form i need it to be returned in the following form:

"childId" : 777 ,

I tried to add at the end of the index, [1] and it is still returning the same form..

Best answer by mathurambm639546

Hi,
Instead of adding [1] at the end of the index, index the value from the rule result. Refer to the below snippet.

childId: index(
      /*calling rule*/rule!AA_QR_getVehicleStatus(
        refStatusId: index(local!status, "id", null())
      )['recordType!{c40f19ec-824f-4377-8d6f-60c072fa9721}AA Vehicle Status.fields.{c84004ba-e283-4b93-90d8-b6faf7561625}sortOrder'],
      1,
      null()
    )

4 replies

December 28, 2023

Hi,
Instead of adding [1] at the end of the index, index the value from the rule result. Refer to the below snippet.

childId: index(
      /*calling rule*/rule!AA_QR_getVehicleStatus(
        refStatusId: index(local!status, "id", null())
      )['recordType!{c40f19ec-824f-4377-8d6f-60c072fa9721}AA Vehicle Status.fields.{c84004ba-e283-4b93-90d8-b6faf7561625}sortOrder'],
      1,
      null()
    )

venkatrea696188
December 29, 2023

I don't understand why it's coming in list when we retrieving only one value.

December 29, 2023

Hi Venky,

If I'm not mistaken, querying the record type and indexing a particular field will return the result as a list, even if it's a single value of any type.

If we pass the result to another expression rule/interface via a rule input of a single type, it will be considered as a single value (Indexing is not required here). In the above scenario, we need to explicitly index the value to avoid the list type.

Reference Link: https://docs.appian.com/suite/help/23.4/fnc_system_queryrecordtype.html#returns