cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

inserting textfield and label values to datatable(postgres)

VK_9460892
7-Bedrock

inserting textfield and label values to datatable(postgres)

Hi everyone,

I need to insert value of numerous textfield entered by user on runtime and value of label (given at time of mashup creation) into postgres database.

I have earlier created code and was successful in transferring data from excel to postgres database, but now as data is not present at one location, I am clueless in achieving it.

Can someone suggest please. I am attaching sample mashup showing labels and textfields.

Thanks in advance.

ACCEPTED SOLUTION

Accepted Solutions

Seems like you already have the service and schema in place, to take text field data into service as an input just click on the text field on the mashup design area and click on the icon displayed on the top left of the widget. It will give you an option to select the inserted text value. Drag this text to the service input in the data panel on the right side of the design area(see below screenshot). Labels do not contain any value(generally the label value will not change), so ideally Label text will be fixed, you can insert the label value directly in the service code.

 

mnarang_0-1619418189229.png

 

View solution in original post

11 REPLIES 11

You can have a sql type service on the DB thing(which connects to your required DB). create a table and schema in the DB, according to your inputs from the mashup text field. Take required inputs in the service for ex textfield1,textfield2..etc. Map each text field value to the input in the service on the mashup. On the final submit button click call this service which will basically take all the input values from text field and insert these values to DB using the SQL command service.

Hi @mnarang,

Thanks for your response. I have already created dbthing, table and schema. i am able to insert data into table directly by giving input into service having sql command.

Only issue/challenge is that I don't know how to map values Map each text field value & label value to the input in the service on the mashup. Kindly suggest or share an example.

This is the code i have written where I am taking datashapeforupload in input:

 

var tableLength = datashapeforupload.rows.length;

if(tableLength!=0) {

for (var x = 0; x < tableLength; x++)
{
var_sheetno = datashapeforupload.rows[x].sheetno;
var_lotno = datashapeforupload.rows[x].lotno;
var_bombtype = datashapeforupload.rows[x].bombtype;
var_bombsno = datashapeforupload.rows[x].bombsno;
var_opt = datashapeforupload.rows[x].opt;
var_date = datashapeforupload.rows[x].date;
var_description = datashapeforupload.rows[x].description;
var_instrument = datashapeforupload.rows[x].instrument;
var_tresult = datashapeforupload.rows[x].tresult;
var_remarks = datashapeforupload.rows[x].remarks;


// result: INFOTABLE dataShape: ""
var result = Things["dbgraphs"].plantconfigpush({
sheetno: var_sheetno ,
lotno: var_lotno,
bombtype: var_bombtype ,
bombsno: var_bombsno,
opt: var_opt,
date :var_date,
description:var_description,
instrument: var_instrument,
tresult:var_tresult,
remarks: var_remarks
});

 

 

plantconfigpush service in dbgraphs thing then inserts data into db.

Seems like you already have the service and schema in place, to take text field data into service as an input just click on the text field on the mashup design area and click on the icon displayed on the top left of the widget. It will give you an option to select the inserted text value. Drag this text to the service input in the data panel on the right side of the design area(see below screenshot). Labels do not contain any value(generally the label value will not change), so ideally Label text will be fixed, you can insert the label value directly in the service code.

 

mnarang_0-1619418189229.png

 

Hi @mnarang ,

 

I did the exact same thing. mapped all texts to input in service given below:

 

//start of code of service


var_sheetno=i_sheetno;
var_lotno = i_lotno;
var_bombtype = i_bombtype;
var_bombsno = i_bombsno;
var_opt = i_opt;
var_date =i_date;
var_description = i_description;
var_instrument = i_instrument;
var_tresult = i_tresult;
var_remarks = i_remarks;


// result: INFOTABLE dataShape: ""
var result = Things["dbgraphs"].plantconfigpush({
sheetno: var_sheetno ,
lotno: var_lotno,
bombtype: var_bombtype ,
bombsno: var_bombsno,
opt: var_opt,
date :var_date,
description:var_description,
instrument: var_instrument,
tresult:var_tresult,
remarks: var_remarks
});

 

 

//end of code of service

 

But still this is not working. I am able to send data from service containing sql command to database, but data is not going when entered from mashup. Please suggest.

I hope you are also executing the "checktry" service - may be on click event of submit for approval button?

Yes @mnarang , on click of button, I am executing "checktry" service only. 

is my code and approach fine?

I have no clue, why this is not working

Your approach seems to be fine, let's try to debug this. Can you put some loggers in your service for every input like logger.info("first input" +firstinput);. After putting loggers at every possible level, try to execute the service from mashup again. Once it executed check the script logs(in info mode) and see if the values being passed in the mashup(text field) are going in or not.

@mnarang 

thanks for this logging idea. I tried this and got an error in scripting log attached with response.

error received is http-nio-8081-exec-15. Do you have any idea regarding this error or its possible fix?

it is difficult to tell the exact problem just on the basis of this error. but there is some issue with your service. If possible can you attach the minimum entities possible to reproduce this issue? If I can reproduce, then I can definitely solve this. Or else you can also open a support case if you want support on call.

I raised a ticket but above mentioned error resolved on its own and I got a solution to my problem which was similar to the one you suggested above. Thanks @mnarang for your support!!!

Announcements


Top Tags