So I've been trying to check each message from a sql table. My sql table structure is down below:
Example:
| id | | triggervalue | | triggermessage |
| 633666515413237791 | | hello, world, test | | Trigger works! |
(array like string is something like: hello, world, test)
I want to check each message from each triggervalue column to see if message contains a string from array like string.
Here is what I've done:
I tried to merge every single array like string then send(triggermessage) where the same row of the found array contains, then checking for word.
connection.query(`SELECT * FROM triggervalue`, (err, rows) => {
let array = []
for(i = 0; i < rows.length; i++) {
let received = rows[i].jsonstring;
var intarray = received.replace(/^\[|\]$/g, "").split(", ");
array.concat(intarray)
// continue code here...
}
})
However, I can't get the triggermessage of the same row of found array. How would I go for it? I've been stuck here for quite a while... Sorry if this way of asking is wrong, thanks!
(Sorry if my english is bad)
Related
I need to storetext all lines from a table where CODICE CATASTALE have a value
I add an image to show, I need to save all line in variable with storetext with this characteristic CODICE CATASTALE have a value, in the image I add 1 - 2 - 3 - 4 to explain line to store.
This is a relative storetext when CODICE CATASTALE have a value stored the line.
Here the page
nonsolocap.it/cap?k=56040
Image
After the execution such script in Selenium IDE table variable will contain data from the table. xpath_to_all_rows_with_CODICE_CATASTALE should be replaced with corresponding xpath.
store xpath count | xpath = xpath_to_all_rows_with_CODICE_CATASTALE | n
store | 0 | j
while | ${j} < ${n} |
store | | rowElement
store | 0 | i
while | ${i} < 7 |
store text | xpath = xpath_to_all_rows_with_CODICE_CATASTALE[${j}]/td[${i}] | element
execute script | if (${i} != 0) var arr = ${rowElement}; else var arr = []; var element = ${element}; arr.push(element); return arr; | rowElement
execute script | return Number(${i}) + 1; | i
end| |
execute script | if (${j} != 0) var arr = ${table}; else var arr = []; var rowElement = ${rowElement}; arr.push(rowElement); return arr; | table
execute script | return Number(${j}) + 1; | j
end| |
use scvSave command and give a name for the target for divide raws
What I want: Columns with Weekdays in Kendo grid where each column may or may not coming from DB. Also, batch edit/Update functionality. Is this feasible somehow if so any help will be appreciated to get me started else any other suggestion, please?
In DB:
Date | in | out | User ID
5/1/2017 | datetime | datetime | int
5/3/2017 | datetime | datetime | int
5/5/2017 | datetime | datetime | int
Output:
User Name | 5/1/2017 | 5/2/2017 | 5/3/2017 | 5/4/2017 | 5/5/2017
Where cell for [5/1/2017], [5/3/2017] and [5/5/2017] will be editable.
It is possible to define the grid column schema dynamically where:
for (var i = 0; i < 5; i++) {
var entryIndex = "entries[" + i + "]";
columns.push({
field: entryIndex,
title: "Column " + i
});
}
would become something like:
// first column for username
columns.push({ field: valuesFromDatabase.UserName });
// loop to append each available date in the list as a column
for (var i = 0; i < valuesFromDatabase.Dates; i++) {
columns.push({
field: i.NumberOfVisits,
title: i.Date
});
}
valuesFromDatabase being a list of objects holding your data (Dates containing a list of whatever content you wish to show in the associated column, in this example a number of visits). I haven't got a chance to test this but it should get you on the right track.
A few other examples of dynamically creating columns:
JSFiddle with editable grid
Example using Razor
I have an issue and i'm looping on it! :| I hope someone can help me..
So i have an input file (.xls), that is simple but there are a row (lets say its "ROW1") that is like this:
ROW1 | ROW2 | ROW3 | ROW_N
765 | 1 | AAAA-MM-DD | ...
null | 1 | AAAA-MM-DD | ...
null | 1 | AAAA-MM-DD | ...
944 | 2 | AAAA-MM-DD | ...
null | 2 | AAAA-MM-DD | ...
088 | 7 | AAAA-MM-DD | ...
555 | 2 | AAAA-MM-DD | ...
null | 2 | AAAA-MM-DD | ...
There are no stardard here, like you can see.. There are some lines null (ROW1) and in ROW2, there are equal numbers, with different association to ROW1 (like in line 5 and 6, then in line 8 and 9).
My objective is to copy and paste the values from ROW1, in the ROW1 after when is null, till isn't null. Basically is to copy form previous step, when is null...
I'm trying to use the "Formula" step, by using something like:
=IF(AND(ISBLANK([ROW1]);NOT(ISBLANK([ROW2]));ROW_n=ROW1;IF(AND(NOT(ISBLANK([ROW1]));NOT(ISBLANK([ROW2]));ROW_n=ROW1;ROW_n=""));
But nothing yet..
I've tried "Analytic Query" but nothing too..
I'm using just stream a xls file input..
Tks very much, any help is very much appreciiated!!
Best Regardsd!
Well i discover a solution, adding a "User Defined Java Class" with the code below:
import java.util.HashMap;
private FieldHelper output_field, card_field;
private RowSet out, log;
private String previou_card =null;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
if (first)
{
first = false;
out = findTargetRowSet("out");
output_field = get(Fields.Out, "previous_card");
} else {
Object[] r = getRow();
if (r == null) {
setOutputDone();
return false;
}
r = createOutputRow(r, data.outputRowMeta.size());
if (previous_card != null) {
output_field.setValue(r, previous_card);
}
if (card_field == null) {
card_field = get(Fields.In, "Grupo de Cartões");
}
String card = card_field.getString(r);
if (card != null && !card.isEmpty()) {
previous_card = card;
}
// Send the row on to the next step.
putRowTo(data.outputRowMeta, r, out);
}
return true;
After this i have to put a few steps but this help very much.
Thank you mates!!
Finally i got result. Please follow below steps
Below image is full transformation screen.
Data Grid Data will be like these. Sorry for that in my local i don't have Microsoft because of that i took Data Grid. Instead of Data Grid you can drag and drop Microsoft Excel Input step.
Drag and Drop one java script step and write below code.
Last step of transformation, drag and drop Select values step and select the columns.( These step is no necessary)
Final result will be like these.
Hope this helps.
I am creating a document from a Template, and cannot figure out how to insert a table at the right position.
I have the table in memory as a 2D array, and in the template I have place-holders like this (including the square-brackets):
...
[TABLE 1]
...
[TABLE 2]
...
[TABLE 3]
...
Each of these placeholders is in a 1x1 table.
I have managed to insert my first array in the right position, but when I then search for the following placeholders my array always gets inserted after Table 1.
My code is the following (I found this online and adapted it slightly):
function insertTable(targetdoc, stringToReplace, tableValues) {
var body = targetdoc.getBody();
var searchElement = targetdoc.getActiveSection();
var searchType = DocumentApp.ElementType.TABLE;
var searchHeading = DocumentApp.ElementType.TABLE_CELL;
var searchResult = null;
// Search until the table is found.
while (searchResult = searchElement.findElement(searchType, searchResult)) {
var par = searchResult.getElement().asTable();
var tabletext = par.getText();
var substr=tabletext.search(stringToReplace);
if (substr >0 ) {
var childindex = body.getChildIndex(par);
var oTable = body.insertTable(childindex+1, tableValues);
return oTable;
}
}
}
and the calling code is:
var oTable = insertTable(oOutputFile,"["+cFieldID+"]",aTable);
where oOutputfile is the new doc, cFieldID is the placeholder text, and aTable is the 2D array.
Can anyone help me get this to work, so that it inserts each array into the correct position?
Thanks
I have written something very similar that might prove useful to you, see GAS Template Engine
It will accept any JSON string and replace place holders in a document that match the structure of the JSON. When an array is encountered, the script looks for a place holder in a table and it will create table rows for each element of the array.
So if your JSON string contains an array as below :
var json = { myarr : [ { col1: "a", col2 : "b" }, { col1 : "c", col2 : "d" }] }
then the script will look for a table in the template document that looks like this :
------------------------------------------------------
| $myarr.col1 | $myarr.col2 |
-------------------------------------------------------
and transform that into :
-----------------------------------
| a | b |
-----------------------------------
| c | d |
-----------------------------------
it will keep the formatting of the rows as well.
It is just a proof of concept for a templating engine but it should be enough to solve your problem.
Thanks koma for your solution which I will certainly use in future, however it was a bit of overkill for what I was looking for.
Finally, I found the solution to what I needed after a mammoth debugging session, and my function shown above has now become:
function insertTable(targetdoc, stringToReplace, tableValues) {
var oDoc = targetdoc.getBody(); // Document
var oSR = oDoc.findText(stringToReplace); // SearchResult
var oPara = oSR.getElement().asText().getParent(); // Paragraph
var nIndex = oDoc.getChildIndex(oPara); // Index
var oTable = oDoc.insertTable(nIndex, tableValues); // Table
return oTable;
}
so, for example, if I have a doc (oDoc) with the following placeholder
[TABLE 1]
an array
aData: {{"","column 1","column 2"},{"row 1","data 11","data 12"},{"row 2","data 21","data 22"}}
and a variable
cFieldID = "TABLE 1";
and call my function
oTable = insertTable(oDoc, cFieldID, aData);
oOutputFile.replaceText("\\["+cFieldID+"\\]","");
I obtain the following in lieu of the placeholder text
-----------------------------------
| | column 1 | column 2 |
-----------------------------------
| row 1 | data 11 | data 12 |
-----------------------------------
| row 2 | data 21 | data 22 |
-----------------------------------
This is less generic and powerful than koma's solution, but sufficient for what I need for now.
Chris
i have in my DB table TBus fields like s1,s2.s3.s4,...sn
i get the seatNumber as a parameter and want to get that field just like i have it in my code.
Any idea please.
private string checkSeatValue(int busTripId, int seatNumber)
{
string sNumber = "s" + seatNumber.ToString();
// Some code here
string sqlCommand = "SELECT " + sNumber + " FROM TBus WHERE Id=" + busTripId + "";
// More code here
}
If you want pure Linq2SQL code, you should get the TBus object:
var bus = yourDataContext.GetTable<TBus>().Where(bus => bus.BusTripId == busTripId).SingleOrDefault();
And then switch your seat variable to get the desired field:
var seat;
switch(seatNumber)
{
case "s1":
seat = bus.Seat1;
break;
case "s2":
seat = bus.Seat2;
break;
// And so it goes on...
}
However, you can do pure SQL code via Linq also or play with reflection.
-- EDIT
As I said in the comment, I believe your database model can be improved. My advice would be having two tables:
TBus Table
TBusId - int [PK]
...
TBusSeat Table
TBusSeatId - int [PK]
TBusIs - int [FK referencing TBus.TBusId]
SeatNumber - int
...
That way, you have more natural flexibility to deal with those king of situations. Consider the following set of data:
TBus Table
TBusId
------
1
2
TBusSeat Table
TBusSeatId | TBusId | SeatNumber | PassengerName
------------------------------------------------
1 1 1 Josh Doe
2 1 2 John Doe
3 1 3 Jane Doe
4 2 1 Jack Doe
So, to deal with your desired query with Linq2SQL, it would be simple as this:
var seat = yourDataContext.GetTable<TBusSeat>().Where(seat => seat.TBusId == 1 && seat.SeatNumber == 2).SingleOrDefault();
And calling seat.PassengerName would result in John Doe.