Web API to Update Data of DB

Certified Lead Developer
Hi,
I have a requirement where i need to Update the data of the Database using Web-API, for that i created a Web API using POST method having a!writeToDataStoreEntity() function configured.

Problem Statement:- when i pass the JSON Format data into body field of Web API, it works Well, but whenever i am trying to do the same using an Expression rule where i have defined a rule input of type text where specified value is the same JSON which i used earlier, then nothing gets Update in database and also no log informations about it, and it returns Writer Type followed by following Value
[name=httpwriter_appian_internal, parameters=http://localhost:port/suite/webapi/storeEmployee; POST; ; ; [username=[externalSystemKey=mycredentials, fieldKey=username, usePerUser=false], password=[externalSystemKey=mycredentials, fieldKey=password, usePerUser=false], preemptive=true];followed by Data
...

OriginalPostID-244534

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    ...
    Below is the code which i have written inside Expression rule
    ====================================================
    load(

    /*local!a: bind(
    get: "null",
    set: */a!httpWrite(

    url: "localhost:myPortNumber/.../storeEmployee",
    method: "POST",
    body: /*a!toJson(*/
    ri!empDetails
    /*)*/,
    basicAuthenticationCredentials: a!httpAuthenticationBasic(
    username: a!scsField(
    externalSystemKey: "mycredentials",
    fieldKey: "username"
    ),
    password: a!scsField(
    externalSystemKey: "mycredentials",
    fieldKey: "password"
    ),
    preemptive: true
    )
    )/*
    ),
    local!a*/
    )
    =========================================================
    Also when i uncomment bind() then getting following error, Expression evaluation error at function 'bind' [line 5]: Invalid parameter: the parameter given as the 'set' parameter to the function 'bind' must not be nu...
  • 0
    Certified Lead Developer
    ...ll and must be a reference to a rule or function that returns Writer

    but as we can see 'set' parameter is not null as well as it's of Type Writer

    please help me to resolve this
  • You have to put this in a saveInto on a SAIL form to get it working. See

    forum.appian.com/.../Evaluation_Functions.html

    But, are you aware of the new smart service functions which allow you to write to DB on SAIL forms?
  • 0
    Certified Lead Developer
    @stefanh791 thanks for your suggestions, i separated httpWrite() into a expression rule, and invoked bind() from saveInto on a SAIL, and also one more problem which i identified was if we convert CDT to Json using toJson() function because in Web API i used fromJson() that means expecting the data to come in JSON Fromat Only, and if CDT Contains Date Field then it used to get convert into 'yyyy-mm-dd' format which is an Invalid Appian Date format, and hence it was raising an error, so i created a Plugin which can modify the Json Data and convert respective given Date Property values to Respective Our Specified (Appian Format) and will return the Complete Valid JSON Text data, which i pushed into httpWrite body, and my problem is got resolved. I will try to share that Plugin to Forum

    Thanks for Your Support
  • I do not understand why you would need a plugin to convert a date from/to JSON. Something like fromJson(toJson(now())) will result in a proper Appian date value.
  • 0
    Certified Lead Developer
    @stefanh791 Actually i was pulling the Complete Employee Details from DB using Web API in Json Format, which contains DOB as well as JoinDate of Type Date , also created a WEB API to update the Employee details, and i was needed to send the Data also in JSON format to Web API in order to get updated, so in such case my existing DOB and Join Date was getting convert into 'yyyy-mm-dd' format while using toJson() which was causing the issue. So the requirement was finally in need to send the Whole CDT in form of JSON where the Existing Date Values must be in Appian format, so for that i created a plugin which did my Job, And Not only for this requirement but also in Any case if we have a Json and need to convert any Date type property value to some other format this can be useful.

    Thanks