When retrieving a sheet via the C# SDK all the cell values are null. Is there an access level for the API or does the C# SDK have a bug? I can get the column names and id's fine.
SmartsheetClient ss = new SmartsheetBuilder().SetAccessToken(myToken).Build();
long sheet_ID = 0000000000000000;
Sheet sSheet = ss.SheetResources.GetSheet(sheet_ID, null, null, null, null, null, null, null);
lblFeedback.Text = "Sheet: " + sSheet.Name + " <br>Rows: " + sSheet.Rows.Count.ToString();
That works fine, so I know I'm accessing the sheet I want, so does the example column map from https://github.com/smartsheet-samples/csharp-read-write-sheet/blob/master/csharp-read-write-sheet/Program.cs
However...
Cell completedCell = getCellByColumnName(r, "Completed", columnMap);
string cellValue = completedCell.DisplayValue;
cellValue is null.
Any cell property, except ColumnId comes back null. What am I doing wrong?
What value is in your cell?
Suggestions:
In the debugger, take a look at the row object and all the cells.
Use a tool like Postman to make the call and examine the results
Related
We have to update value of a smartsheet Cell. This Cell contains Hyperlink to a different sheet. Hyperlink URL is assigned. We want to update this cell value by Smartsheet API C# SDK.
If I'm understanding your scenario correctly, a cell in your sheet contains a hyperlink to another Smartsheet sheet (as described here), and you want to update that cell value to be a hyperlink that points to a different sheet in Smartsheet. The following code uses the Smartsheet C# SDK to accomplish that.
// Replace the second parameter here with your API Access Token
System.Environment.SetEnvironmentVariable("SMARTSHEET_ACCESS_TOKEN", "replace-this-string-with-your-API-access-token");
SmartsheetClient smartsheet = new SmartsheetBuilder().Build();
// Specify updated cell value (hyperlink to another sheet)
var cellToUpdate = new Cell
{
ColumnId = 6101753539127172, // ID of the column that contains the cell you're updating
Value = "text-value-for-hyperlink", // text value of hyperlink to display in the cell -- typically set to the target Sheet's name
Hyperlink = new Hyperlink
{
SheetId = 7501762300012420 // ID of the sheet that the hyperlink will point to
}
};
// Identify row and add updated cell object to it
var rowToUpdate = new Row
{
Id = 4324392993613700, // ID of the row that contains the cell you're updating
Cells = new Cell[] { cellToUpdate }
};
// Issue the 'update row(s)' request
IList<Row> updatedRow = smartsheet.SheetResources.RowResources.UpdateRows(
3932034054809476, // ID of the sheet that you're updating
new Row[] { rowToUpdate }
);
Hopefully this is helpful. If I'm not understanding your scenario correctly, please comment on this answer to elaborate further about your scenario.
** UPDATE - replacing the sheet hyperlink with another type of value **
Please note, if you want to remove the sheet hyperlink from the cell and replace it with another value, you should specify an empty Hyperlink object in the request, as shown in the following code.
// Specify updated cell value (just a text value -- i.e., no longer a sheet hyperlink)
var cellToUpdate = new Cell
{
ColumnId = 6101753539127172, // ID of the column that contains the cell you're updating
Value = "new-cell-value",
Hyperlink = new Hyperlink()
};
I'm trying to check if I'm binding a null data on a controller. If the data is null, I need to not show the label as well as the binded data.
Below is my code right now.
var oMatNrRow1 = new sap.ui.commons.layout.MatrixLayoutRow();
control1 = new sap.ui.commons.Label({
text : Appcc.getText("MATERIAL_NO") + ":"
});
matrixCell1 = new sap.ui.commons.layout.MatrixLayoutCell();
matrixCell1.addContent(control1);
control = new sap.ui.commons.Label();
control.bindProperty("text", "matnr");
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
I have tried control.getProperty("text") but it only returns null when it should have return a number if matnr is not null.
I also tried formatter. I will have no problem with formatter if matnr is not null. But if it is null, the point is to destroy/delete contents of both matrixCell1 instances. In my code below, addition of matrixCell1 content will still push through.
...
formatter: function(matnr){
if (matnr !== ''){
return contract
} else{
matrixCell.destroyContent();
}
});
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
Not sure if you can move the ff code inside if statement
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
Any ideas are appreciated.
I would also suggest to user the visible property.
Are you aware of conditional binding of UI5? Using them you do not need the formatter at all in that case. see
Found a workaround on my issue. It was a simple if else condition. For the if statement, I just added data[j].matnr and it worked! I also noticed that this was how SAP implemented the behavior also e.g. oSearchViewData.description.
I am trying to read data using the Smartsheet API from Java to create different formats, such as reports & labels with the data from one row.
I've set up my IDE (NetBeans) so that the API samples work for me, but they are all about creating new sheets etc and I can not figure out how to read the contents of an existing sheet.
I would have thought that I could read the entire sheet into a java object in one line of code, but it appears more complicated than that, and I can not find any applicable documentation anywhere. The Javadoc does not say where/how to get the relevant IDs, what any of the inclusion or exclusion objects actually do, or which are required or optional etc.
Are there any examples of reading the contents of a sheet from java available?
I know that this is a bit of a broad question, but I'm totally stumped.
Thanks Kim!
For others, here's what worked for me. This code gets a list of the sheets in my account and displays the contents those with names starting with "Specs - " :
import com.smartsheet.api.Smartsheet;
import com.smartsheet.api.SmartsheetBuilder;
import com.smartsheet.api.SmartsheetException;
import com.smartsheet.api.models.Cell;
import com.smartsheet.api.models.Column;
import com.smartsheet.api.models.PagedResult;
import com.smartsheet.api.models.Row;
import com.smartsheet.api.models.Sheet;
import com.smartsheet.api.oauth.Token;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SampleCode {
/*
Show the contenst of all sheets whose name starts with "Specs - "
*/
public static void main(String[] args) {
final String delimiter = ", ";
// Create a Smartsheet object with our Access Token
Token token = new Token();
token.setAccessToken(Private.TOKEN);
Smartsheet smartsheet = new SmartsheetBuilder().setAccessToken(token.getAccessToken()).build();
//get a paged list of all Sheets, using null Source Inclusion & Pagination parameters
PagedResult<Sheet> homeSheets = new PagedResult<>();
try {
homeSheets = smartsheet.sheetResources().listSheets(null, null);
} catch (SmartsheetException ex) {
Logger.getLogger(SampleCode.class.getName()).log(Level.SEVERE, null, ex);
}
// get a Java List<Sheet> from the PagedResult<Sheet>
List<Sheet> sheetInfoList = homeSheets.getData();
// Loop through each sheet in the list
for (Sheet sheetInfo : sheetInfoList) {
String sheetName = sheetInfo.getName();
// Show data for all sheets with names that match our pattern
if (sheetName.startsWith("Specs - ")) {
// get the sheet object, with no optional includes or excludes
Sheet theSheet = null;
try {
theSheet = smartsheet.sheetResources().getSheet(sheetInfo.getId(), null, null, null, null, null, null, null);
} catch (SmartsheetException ex) {
Logger.getLogger(SampleCode.class.getName()).log(Level.SEVERE, null, ex);
}
// Print the sheets name
System.out.println("\nSheet: " + theSheet.getName() + "\n");
// Print the column titles as a delimited line of text.
List<Column> columnList = theSheet.getColumns();
String columnHeader = null;
for (Column col : columnList) {
columnHeader = columnHeader == null ? col.getTitle() : columnHeader + delimiter + col.getTitle();
}
System.out.println(columnHeader);
// Print each row as a delimited line of text.
List<Row> rowList = theSheet.getRows();
for (Row row : rowList) {
List<Cell> cellList = row.getCells();
String rowOutput = null;
for (Cell cell : cellList) {
String cellOutput = Objects.toString(cell.getValue() != null ? cell.getValue() : cell.getDisplayValue());
rowOutput = rowOutput == null ? cellOutput : rowOutput + delimiter + cellOutput;
}
System.out.println(rowOutput);
}
}
}
}
}
The Smartsheet API documentation contains sample code that shows how to use the Java SDK. The Java Sample Code section in the docs describes how to establish the connection, etc. Then, each operation within in the "API Reference" section shows sample code (in the "Java" tab of the panel on the right side of the page) for executing the operation using the Java SDK.
To get Sheet data you'll use the "Get Sheet" operation. As described in the API docs, here's the Java SDK sample code for that operation:
// Get sheet (omit all parameters).
smartsheet.sheetResources().getSheet(sheetId, null, null, null, null, null, null, null);
The "sheetId" parameter should be the ID of the Sheet which you want to retrieve. You can either get this ID programmatically (i.e., by using an operation like "List Sheets", for example) -- or you can get it manually via the Smartsheet UI as described in this help article. The other parameters (all set to "null" in the sample code) represent the 7 parameters described in the API documentation for this operation. I imagine intellisense in your IDE should indicate the sequence of those parameters expected by the getSheet function, as well as valid values for each parameter (but the API docs will explain the meaning of each parameter).
I have some list that gets filled with rows by ajax call,
above it I have an itemCount span - to show how many rows we have.
After the table is filled by rows, the itemCount span value is updated.
what I try to do is to copy this itemCount value, to add a new item to
the list and then to test that the new itemCount value is bigger by 1
than the old one.
The problem, I think, is that when I take the first value from the itemCount
span, it is still empty.
I tried to add browser.waitForAngular();, etc, but the value is still empty:
element(by.id('itemsCount')).getText().then(function(text) {
console.log('**********' + text);
});
what I see is just: '**********'
Thanks for any help !
you could try using the expected conditions like this.
var itemsCount = element(by.id('itemsCount'));
var blank = EC.textToBePresentInElementValue(itemsCount, '');
var itemsNotEmpty = EC.not(blank);
browser.wait(itemsNotEmpty, 5000, "✗ Failed to wait for the item count load").then(function() {
itemsCount.getText().then(function(text) {
console.log('**********' + text);
});
});
Basically wait till the itemsCount isn't blank anymore then get it's text.
There is some different between getText() and getAttribute(), depending on what sort of field it is. Can you try getAttribute and see if it grabs the text?
I am using jqgrid in my new project.
In a specific case I need to use a select element in the grid. No problem.
I define the colModel and the column for example like (from wiki)
colModel : [
...
{name:'myname', edittype:'select', editoptions:{value:{1:'One',2:'Two'}} },
...
]
But now when I load my data I would prefer the column "myname" to contain the value 1.
This won't work for me instead it has to contain the value "One".
The problem with this is that the text-part of the select element is in my case localized in the business layer where the colModel is dynamically generated. Also the datatype for the entity which generates the data via EF 4 may not be a string. Then I have to find the correct localized text and manipulate the data result so that the column "myname" does not containt an integer which is typically the case but a string instead with the localized text.
There is no option you can use so that when the data contains the value which match an option in the select list then the grid finds that option and presents the text.
Now the grid presents the value as a text and first when I click edit it finds the matching option and presents the text. When I undo the edit it returns to present the value again.
I started to think of a solution and this is what I came up with. Please if you know a better solution or if you know there is a built in option don't hesitate to answer.
Otherwise here is what I did:
loadComplete: function (data) {
var colModel = grid.getGridParam('colModel');
$.each(colModel, function (index, col) {
if (col.edittype === 'select') {
$.each(grid.getDataIDs(), function (index, id) {
var row = grid.getRowData(id);
var value = row[col.name];
var editoptions = col.editoptions.value;
var startText = editoptions.indexOf(value + ':') + (value + ':').length;
var endText = editoptions.indexOf(';', startText);
if (endText === -1) { endText = editoptions.length; }
var text = editoptions.substring(startText, endText);
row[col.name] = text;
grid.setRowData(id, row);
});
}
});
}
It works and I will leave it like this if nobody comes up with a better way.
You should just include additional formatter:'select' option in the definition of the column. See the documentation for more details.