var week = me.GetWeekNumber({ date: when }); // Copied from Stack Overflow, didn't test its correctness
var month = when.getMonth(); // Zero-based
var year = when.getFullYear();
var correctmonth = month +1;
var query = me.CreateValuesWithData({ values: {
value: value,
Kategory: Kategory,
Department:Department,
Line: Line,
SKU : SKU,
KPI_Details: KPI_Details,
Target: Target,
Other_Target : Other_Target,
Other_value : Other_Value,
week: week,
month: correctmonth,
year: year
} });
query.id = me.ID;
var params = {
sourceType: undefined /* STRING */,
values: query /* INFOTABLE*/,
location: undefined /* LOCATION */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
};
if(me.ID !== query.id){
stop();
}
var result = me.AddDataTableEntry(params);
when I refresh the page, it will auto increment one more empty row in the grid widget.
how to fix this problem?
What exactly are you trying to accomplish?
Nothing in your code shows any sort of 'auto increment' of a primary key. This isn't something that Thingworx supports (compared to an SQl db).
I recommend if you need to track unique records, assign the Primary fields in the DataShape
if you just need to tag unique records, use GenerateGUID to assign a GUID per record
Perhaps if you explain your use case that could help generate proper recommendations.
Hi @PaiChung,
I just want to make sure everytime I refresh the page, primary key cannot auto increment and once I click "add" button, the new data will show in the grid widget. Primary key should be in sequence.
Hello,
Why don't you increment your primary key directly in the service which adds new record, right before adding it?
/ Constantine
If a page refresh is creating a record, then I would revisit your flow of services.
Sounds like you are trying to generate a placeholder which unfortunately becomes an actual record.
If you are just looking to create records with unique IDs I would just provide input fields and generate the ID upon 'commit'.
If you want to have it in a 'table' You can always generate dummy infotable with one row and use that for input through an editable grid.
this is reference which I refresh the page.
Hi Mr. Xiao,
Actually it seems like each time your mashup is refreshed, your addEntries service is triggered once. While when you refresh the mashup, the inputs are blank, thus you're getting empty records.
2 solutions for your issue:
1. Check out how mashup refresh/ loaded event is affecting the service, stop the triggering binding, problem solved.
2. Your service need several input properties, so define some of the input to be "Required", then even if the service is trigger automatically, the service would fail, and you won't get blank records again, just some script errors.
Hi @zyuan1,
sounds like your solution 1 can work, but if I cancel triggering binding, my input cannot be successful. maybe Could u check my coding? is there any changes I need to make? I think main issue is coding.Thank you.
I don't know what's this doing
if(me.ID !== query.id){
stop();
But other parts of your script are very general service input configurations, so I still doubt the error in binding.
What do you mean by saying "if I cancel triggering binding, my input cannot be successful" ?
This service should only be triggered by Pressing the Add button, the input parameter bindings should be remained.
While if this doesn't work, I'd suggest you create a TS case since the behavior seems odd.
here is my binding. Maybe here is some problem. Please help me to check it again. thank you
here is my latest code. Still have some problem.
var week = me.GetWeekNumber({ date: when }); // Copied from Stack Overflow, didn't test its correctness
var month = when.getMonth(); // Zero-based
var year = when.getFullYear();
var correctmonth = month +1;
id = me.GetDataTableEntryCount();
me.AddDataTableEntries({ values: me.CreateValuesWithData({ values: {
id:id+1,
value: value,
Kategory: Kategory,
Department:Department,
Line: Line,
SKU : SKU,
KPI_Details: KPI_Details,
Target: Target,
Other_Target : Other_Target,
week: week,
month: correctmonth,
year: year
} }) });
Cancel the Mashup-loaded binding to Execute AddorUpdateDatatableEntries service, that's what I'm talking about.
Shouldn't your service be triggered by the Add button - click event?
But in your 1.JPG screenshot it's not. Fix it and check.