Retrieve primary key after WriteToDataStoreEntity on WebApi

Hi,

I use the function writeToDataStoreEntity on a WebApi and I am wondering how to retrieve the generated value of the primary key after execute the write to data store entity data service.

 

Thanks you for you help,

Charlène

  Discussion posts and replies are publicly visible

Parents
  • HI All,

     

    Writetodatastoreentity Function works same as smart service, once the insert or what ever the operation is doe it will return the output value. If it is an insert in output value you will find the auto generated key value. Please see below simple example.

    with(
      local!value:{
      'type!{urn:com:appian:staticData}staticDataAuditDetails'(
        id:null,
        TableName:"My Table",
        Operation:"Insert",
        DateTime:now(),
        AppianUser:"gunawas",
        QueryData:"Insert into bla bla",
        isBackUpTaken:true()
      ),
      'type!{urn:com:appian:staticData}staticDataAuditDetails'(
        id:null,
        TableName:"My Table",
        Operation:"Insert",
        DateTime:now(),
        AppianUser:"gunawas",
        QueryData:"Insert into bla bla",
        isBackUpTaken:true()
      )
      },
      a!writeToDataStoreEntity(   
        dataStoreEntity: cons!TEST_Static_Data_POC,
        valueToStore: local!value,
        onSuccess: a!httpResponse(
          statusCode: 200,
          headers: {
            a!httpHeader(name: "Content-Type", value: "application/json")
          },
          body: a!toJson(
            fv!storedValues  /* This value contain the retun value with inserted rows primary key*/
          )
        ),
        onError: a!httpResponse(
          statusCode: 500,
          headers: {
            a!httpHeader(name: "Content-Type", value: "application/json")
          },
          body: a!toJson(
            {
              error: "There was an error writing to the data store"
            }
          )
        )
      )
    )

     

    When you execute the webAPi The result will be like below

    [ [ {
      "id" : 19,
      "TableName" : "My Table",
      "Operation" : "Insert",
      "DateTime" : "2017-09-04T14:15:14.190+0000",
      "AppianUser" : "gunawas",
      "QueryData" : "Insert into bla bla",
      "isBackUpTaken" : true
    }, {
      "id" : 20,
      "TableName" : "My Table",
      "Operation" : "Insert",
      "DateTime" : "2017-09-04T14:15:14.190+0000",
      "AppianUser" : "gunawas",
      "QueryData" : "Insert into bla bla",
      "isBackUpTaken" : true
    } ] ]

     

    As you can see the result contains the id value returned.

    Hope this clarifies your doubts and questions.

     

    Regards

    Suresh

Reply
  • HI All,

     

    Writetodatastoreentity Function works same as smart service, once the insert or what ever the operation is doe it will return the output value. If it is an insert in output value you will find the auto generated key value. Please see below simple example.

    with(
      local!value:{
      'type!{urn:com:appian:staticData}staticDataAuditDetails'(
        id:null,
        TableName:"My Table",
        Operation:"Insert",
        DateTime:now(),
        AppianUser:"gunawas",
        QueryData:"Insert into bla bla",
        isBackUpTaken:true()
      ),
      'type!{urn:com:appian:staticData}staticDataAuditDetails'(
        id:null,
        TableName:"My Table",
        Operation:"Insert",
        DateTime:now(),
        AppianUser:"gunawas",
        QueryData:"Insert into bla bla",
        isBackUpTaken:true()
      )
      },
      a!writeToDataStoreEntity(   
        dataStoreEntity: cons!TEST_Static_Data_POC,
        valueToStore: local!value,
        onSuccess: a!httpResponse(
          statusCode: 200,
          headers: {
            a!httpHeader(name: "Content-Type", value: "application/json")
          },
          body: a!toJson(
            fv!storedValues  /* This value contain the retun value with inserted rows primary key*/
          )
        ),
        onError: a!httpResponse(
          statusCode: 500,
          headers: {
            a!httpHeader(name: "Content-Type", value: "application/json")
          },
          body: a!toJson(
            {
              error: "There was an error writing to the data store"
            }
          )
        )
      )
    )

     

    When you execute the webAPi The result will be like below

    [ [ {
      "id" : 19,
      "TableName" : "My Table",
      "Operation" : "Insert",
      "DateTime" : "2017-09-04T14:15:14.190+0000",
      "AppianUser" : "gunawas",
      "QueryData" : "Insert into bla bla",
      "isBackUpTaken" : true
    }, {
      "id" : 20,
      "TableName" : "My Table",
      "Operation" : "Insert",
      "DateTime" : "2017-09-04T14:15:14.190+0000",
      "AppianUser" : "gunawas",
      "QueryData" : "Insert into bla bla",
      "isBackUpTaken" : true
    } ] ]

     

    As you can see the result contains the id value returned.

    Hope this clarifies your doubts and questions.

     

    Regards

    Suresh

Children