i need to to add a text calculated field in TestTrack, so the field always add itself and then anoter field.
so the field will always contain the previous entry and the new one.
how can i do it ?, without the testtrack claiming its a recursive formula
the only way to dit is to do a count of the event (adding data to the field)
and than run a for each of the ocurrnces with a concatenate of the data with the string itself (old value).
here is the example that works for me :
var TicketCount=Item.Events.count("update ticket");
var ticketsStr ='';
for(ticketIndex = 0;ticketIndex < TicketCount;ticketIndex++)
{
ticketsStr = ticketsStr + Item.Events.at(ticketIndex,"update ticket").fieldValue("Customer Name");
if(ticketIndex < TicketCount-1)
ticketsStr = ticketsStr + ",";
}
result = ticketsStr;
You are correct that a TestTrack calculated field cannot reference itself in the formula. Even if it could reference itself, consider the following formula for "update ticket":
Item.fieldValue("update ticket")+Item.fieldValue("Type")
In this scenario, the Type value would always be appended but there would be no check to see if the Type value is already in the list. Every time an item is edited the "update ticket" field value would be recalculated and the Type value would be appended again whether it has changed or not.
The solution proposed by Tal solves this problem by looping through the other fields and re-building the value. Additionally if a Customer Name value is modified or deleted, the field value will be correctly calculated.
Related
Trying to create a table that checks if the room key is already taken.
Google spreadsheet link.
An employee selects or enters the value into F2 cell. The formula in the G2 cell =IF(ISERROR(MATCH(F2,C4:C350,0)), "Brīvs", "Paņemts") tests whether the key is taken or not. The formula runs through C column and tests for the value.
While matching, it is also triggering the formula in B4 cell. Formula in B4 being =IF(C4>0, now(), "")
Issue is, every time an employee selects/enters the value, the MATCH function triggers the now() function and overrides the newest time if it matches the search criteria.
Is there a way of testing for the value without invoking the now() function so that the time stays as it was? Limiting recalculation counts in spreadsheet settings does not aid since an employee may not enter the value correctly from the 1st time.
Tried putting the value into another cell by "=" to nearby cell and =cell(contents, cell coordinate), but these refer back to the original values and Spreadsheet would recalculate all the references.
Thanks to cOde for providing the hint.
The code below is modified to the following needs. Since the sheets will be subsequently added, the SHEETNAME variable is taken out. I have also added the isBlank option at the end, so that if there is no value in the cell, the timestamp is erased.
/**
* Creates a Date Stamp if a column is edited.
*/
//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 3;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,-1];
function onEdit(e) {
SpreadsheetApp.getActiveSpreadsheet();
var ss= SpreadsheetApp.getActiveSheet();
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
if (selectedCell.isBlank()) {
dateTimeCell.setValue("");
}
}
I'm using a QtableView to display and edit data from a QsqlTableModel.
Everything's fine : data from a postgreSQL table is displayed, and user can edit it and save modifications.
I want to add a row when uses click on a button. I use the insertRecord method from my QslTableModel.
The row is correctly added in the QTableView.
My problem is :
I want to insert a value from a query in the first cell of this new row. (to automatically populate an unique identifier).
This is my code :
def ajoutlgn(self):
query_idNewLine = QtSql.QSqlQuery(self.db)
if query_idNewLine.exec_('SELECT sp_idsuivi+1 FROM bdsuivis.t_suivprev_tablo ORDER BY sp_idsuivi DESC LIMIT 1'):
while query_idNewLine.next():
identifiant = query_idNewLine.value(0)
#print identifiant
record = QtSql.QSqlRecord()
record.setValue(1,identifiant)
self.model.insertRecord(self.model.rowCount(), record)
The value is not inserted in the new row (but if I enter a value by hand, it works perfectly).
Nevertheless, the query is OK (as I can see with the « print identifiant » line, which returns the expected integer).
Do you see what I'm doing wrong ?
Are there other methods to insert programmatically a value in a QTableView cell?
Or do I have to use a QitemDelegate ?
Thanks for advance.
Finally I found the solution :
This line creates a record, but not a record for my QsqlTableModel
record = QtSql.QSqlRecord()
I replaced it with this one, and it works perfectly :
record = self.model.record()
I'm trying to query one item's descendants using following query :
And not getting any items despite the fact that item with specified field value exists?
This query in query analyzer for some reason works:
select * from /sitecore/content/itema/News/descendant::*[#NewsId='235271']
Any help in correcting my code to get back item I'm searching for?
string sitecoreQuery = "descendant::*[#NewsId='" + item.Id.ToString() + "']";
Item[] newsItems = parent.Axes.SelectItems(sitecoreQuery);
Updated based on your comment:
The query looks ok, but you could also try using the shortcut for descendants: //*. I have just tested this locally and it returned me expected items.
string sitecoreQuery = "//*[#NewsId='" + item.Id.ToString() + "']";
Item[] newsItems = parent.Axes.SelectItems(sitecoreQuery);
Also double check that item.Id.ToString() is returning the Id you are expecting.
Hope that helps
You can try the following:
Item[] newsItems = Sitecore.Context.Database.SelectItems(string.Format("/sitecore/content/itema/News//*[#NewsId='{0}']", NewsId));
That should get you the filtered items
for the following method
Uri uri = ContentUris.withAppendedId((MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
i have read many examples but none of the examples tell me what to do with "id" part of the perameter, i don't want to assign which row because that will change depending of what row the specific image is stored in. so i can't hard code "id". how to deal with this? and can i leave the id as null?
edit
i just found this a few minutes ago from a website, http://www.grokkingandroid.com/android-tutorial-using-content-providers/
values.clear();
values.put(Words.WORD, "Zaphod");
Uri uri = ContentUris.withAppendedId(Words.CONTENT_URI, id);
long noUpdated = resolver.update(uri, values, null, null)
here is the quote from the author, "Since I changed only one record, a URI with an appended ID is sufficient. But if you want to update multiple values, you should use the normal URI and a selection clause."
so he says to use a "normal URI and selection clause" so how do i do that?
this is my selection statement:
String selection = MediaStore.Images.Media.DATA + "='" + filename +"'";
where "filename" is a string variable that varies depending on the image selected, for example, in this case /mnt/sdcard/pic09.png
I'm not sure if I understood your question, but regarding the part when you ask how do you do the normal URI and selection clause, the "trick" is that using content providers you dont put the whole selection in one argument as:
String selection = MediaStore.Images.Media.DATA + "='" + filename +"'";
but instead, you introduce the selection type, selection arguments through different input variables. So for example, the
update where MediaStore.Images.Media.DATA equals filename
becomes:
update (uri, contentValues, String selection, String[] selectionArgs)
where uri points to the table (not the row)
content values point to a ContentValues object with your new values
selection must contain the fields to be compared + comparrisson type + question mark, as
MediaStore.Images.Media.DATA + " = ?";
And selection arguments is an array with all the strings replacing question marks on your selection string, so in your case just
{filename}
In the below C++ code, i am updating a field of emp table based on the search value. But this code is not working properly. I am getting output as aborted.
void UpdateData(string field_name,string updated_value,string search_value)
{
stmt->createStatement("UPDATE emp SET :1=:2 where search=:3");
stmt->setString(1,field_name);
stmt->setString(2,updated_value);
stmt->setString(3,search_value);
stmt->executeUpdate();
}
In my program user will select which field they have to update and the selected field name is passed into function as field_name parameter. updated_value is the new value entered by the user and search_value is the search key to find the appropriate record.
If i do like
stmt->createStatement("UPDATE emp SET field_name=:2 where search=:3");
its working..
But the problem is, the field name will change according to user selection. How i can overcome this problem. Is there any other way ?
You can't set the name of the field with the statement->setString() method; only the values of the variables can be bound like that.
I know of only two solutions to achieve this (both aren't particularly nice):
Dynamically create the statement string
string statement ="UPDATE emp SET " + fieldname + "=:1 where search=:2";
Prepare individual statements, each affecting one field and choose at runtime
const string STATEMENT_FIELD_CITY = "UPDATE emp SET CITY=:1 where search=:2";
const string STATEMENT_FIELD_LAND = "UPDATE emp SET LAND=:1 where search=:2";