Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

How to update data in tables Using Java Script?

ramprakasht3196
Level 3
Level 3

I have to update the data which is already available in custom schema using API. For that I am using Below java script snippet.

Workflow is Running without any error. But The data is not updated in tables. Please help me to solve this.

var query = xtk.queryDef.create(

     <queryDef schema= "temp:fileImport" operation="select"> 

     <select>   

     <node expr="firstName"/>

     <node expr="lastName"/>

     <node expr="email"/>

     <node expr="city"/>

     </select>  

  </queryDef>)

var results = query.ExecuteQuery();

for each ( var record in results.fileImport) {

                 logInfo("record --"+record.firstName);

                  xtk.session.Write(<query xtkschema="ram:customer" _operation="update" _key="@firstName" city = {record.city} firstName={record.firstName} />);

 

}

Regards,

Ramprakash.

1 Accepted Solution
Milan_Vucetic
Correct answer by
Community Advisor
Community Advisor

Hi Ramprakash,

It can be that your query doesn't return anything so there is no update.

You may fetch temp schema like this:

var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1);   

logInfo(schemaName); 

var query = xtk.queryDef.create(   

  <queryDef schema={vars.targetSchema} operation="select">   

  <select>  

     <node expr="firstName"/>

     <node expr="lastName"/>

     <node expr="email"/>

     <node expr="city"/>

     </select> 

    </queryDef>); 

If you are sure in this above, you may try this for writing:

var some_variable= <customer

                                      xtkschema="ram:customer"

                                      _key="@firstName"

                                      _operation="Update"

                                      city = {record.city}

                                      firstName={record.firstName}

                                      />;                                                               

xtk.session.Write(some_variable);

View solution in original post

1 Reply
Milan_Vucetic
Correct answer by
Community Advisor
Community Advisor

Hi Ramprakash,

It can be that your query doesn't return anything so there is no update.

You may fetch temp schema like this:

var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1);   

logInfo(schemaName); 

var query = xtk.queryDef.create(   

  <queryDef schema={vars.targetSchema} operation="select">   

  <select>  

     <node expr="firstName"/>

     <node expr="lastName"/>

     <node expr="email"/>

     <node expr="city"/>

     </select> 

    </queryDef>); 

If you are sure in this above, you may try this for writing:

var some_variable= <customer

                                      xtkschema="ram:customer"

                                      _key="@firstName"

                                      _operation="Update"

                                      city = {record.city}

                                      firstName={record.firstName}

                                      />;                                                               

xtk.session.Write(some_variable);

View solution in original post