Getting Multiple Records from Web API

I am integrating an employee system with another system that tracks our employee background checks.  The Web API returns several records for an employee.

body Dictionary
    LASTNAME "Smith"(Text)
    USER_ID 1234567(Number (Integer))
    FIRSTNAME "Bob"(Text)
BGCDATA List of Dictionary - 3 items
 Dictionary
  SERVICENAME "Fingerprinting"(Text)
  TYPENAME "Background Check Option for School Teachers"(Text)
  BGCDATE "July, 25 2018 00:00:00"(Text)
  BGCSTATUS "Complete"(Text)
  BGCCOMMENTS ""(Text)
 Dictionary
  SERVICENAME "MYB"(Text)
  TYPENAME "EMPLOYEE"(Text)
  BGCDATE "October, 24 2023 08:00:26"(Text)
  BGCSTATUS "Complete"(Text)
  BGCCOMMENTS null(Null)
 Dictionary
  SERVICENAME "MYB"(Text)
  TYPENAME "EMPLOYEE"(Text)
  BGCDATE "April, 19 2017 09:22:39"(Text)
  BGCSTATUS "Complete"(Text)
  BGCCOMMENTS null(Null)

Here is the XSD for the CDT that I am storing the data into.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:com:appian:types:PMSO" targetNamespace="urn:com:appian:types:PMSO">
  <xsd:complexType name="PMSO_BGCData">
    <xsd:annotation>
      <xsd:documentation><![CDATA[Background Check Data]]></xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element name="USER_ID" nillable="true" type="xsd:int" />
      <xsd:element name="SERVICENAME" nillable="true" type="xsd:string">
        <xsd:annotation>
          <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="TYPENAME" nillable="true" type="xsd:string">
        <xsd:annotation>
          <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="BGCDATE" nillable="true" type="xsd:string">
        <xsd:annotation>
          <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="BGCSTATUS" nillable="true" type="xsd:string">
        <xsd:annotation>
          <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="BGCCOMMENTS" nillable="true" type="xsd:string">
        <xsd:annotation>
          <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

I have an expression rule that converts the resultant JSON to the CDT.

a!localVariables(
  if (
    a!isNotNullOrEmpty(ri!result),
    'type!{urn:com:appian:types:PMSO}PMSO_BGCData'(
      USER_ID: ri!result.USER_ID,
      /*FIRSTNAME: ri!result.FIRSTNAME,*/
      /*LASTNAME: ri!result.LASTNAME,*/
      SERVICENAME: ri!result.SERVICENAME,
      TYPENAME: ri!result.TYPENAME,
      BGCDATE: ri!result.BGCDATE,
      BGCSTATUS: ri!result.BGCSTATUS,
      BGCCOMMENTS: ri!result.COMMENTS
     
    ),
    null
  )
)

The problem is that I do not get multiple records, just one.  If the resultant is multiple records, I get this from the Expression Rule.

MSO_BGCData
    USER_ID 1234567(Number (Integer))
    SERVICENAME ""(Text)
    TYPENAME ""(Text)
    BGCDATE ""(Text)
    BGCSTATUS ""(Text)
    BGCCOMMENTS ""(Text)

If the resultant API call is a single record, I get this from the Expression Rule.

PMSO_BGCData
    USER_ID 1234567(Number (Integer))
    SERVICENAME "Fingerprinting"(Text)
    TYPENAME "Background Check Option for School Teachers"(Text)
    BGCDATE "July, 25 2018 00:00:00"(Text)
    BGCSTATUS "Complete"(Text)
    BGCCOMMENTS ""(Text)

I am trying to use the USER_ID for each of the nested records.  I am not sure that the result is well formed or I am not doing something correctly.

  Discussion posts and replies are publicly visible

Parents Reply
  • 0
    Certified Lead Developer
    in reply to Hemaashri

    "It was not working" is no great error description!

    If the field names and data types match, you can just cast your list of dictionaries to a list of records.

    cast(
      a!listType('recordType!AA Vehicle'),
      {
        {vehicleid: 1},
        {vehicleid: 2}
      }
    )

    If the field names do not match, or you need to transform data:

    a!forEach(
      items: {
        {id: 1},
        {id: 2}
      },
      expression: 'recordType!AA Vehicle'(
        'recordType!AA Vehicle.fields.vehicleid': fv!item.id
      )
    )

Children
No Data