I have a smartsheet integration where I'm obtaining data from another program via a web service and writing into a sheet. The relevant code to populate the sheet is here:
Cell[] cellsA = new Cell[]
{
new Cell.AddCellBuilder(sheet.Columns[0].Id, projectData[i][0].Trim()).Build() //Project ID
,new Cell.AddCellBuilder(sheet.Columns[1].Id, projectData[i][1].Trim()).Build() //Customer
,new Cell.AddCellBuilder(sheet.Columns[2].Id, projectData[i][2].Trim()).Build() //Description
,new Cell.AddCellBuilder(sheet.Columns[3].Id, projectData[i][3].Trim()).Build() //Status
,new Cell.AddCellBuilder(sheet.Columns[4].Id, startDate).SetStrict(false).Build() //StartDate
,new Cell.AddCellBuilder(sheet.Columns[5].Id, endDate).SetStrict(false).Build() //EndDate
,new Cell.AddCellBuilder(sheet.Columns[6].Id, projectData[i][6].Trim()).Build() //Project Manager
};
// Specify contents of first row.
Row rowA = new Row.AddRowBuilder(null, true, null, null, null).SetCells(cellsA).Build();
My question is, instead of using
sheet.Columns[0].Id
Is it possible to use a column name to identify a specific column instead of the index? The reason being if a user moves or rearranges columns, this will result in errors (date formats, etc.).
Thanks...
You cannot programmatically reference a column by name (even if you could, you probably wouldn’t want to — because name is subject to change, just like position is), but you can programmatically reference a column by ID (which will never change, even if the column is moved or renamed).
Related
I am working on implementing grouping w/ the Server Side Row Model. I need to generate an appropriate ID for the intermediate group rows. For example, if I group by Status then I would have intermediate rows representing each Status (NEW, IN PROGRESS, COMPLETE, etc). I need to come up with a unique ID for these rows (but preferable something deterministic if they need to be accessed/updated later).
The getRowId function is passed an object that contains things like the row's data, the previous parent group values, a reference to the api, etc.
What I would ideally like to know is the current list of group fields... I have all of the values readily accessible, but I don't know what field the current row is being grouped by - else I could just go grab that field from the row's data to use as part of the row id...
Is there any good way to acquire this information?
The columnApi exposes the 'getRowGroupColumns' function from which the field property can be deduced:
getRowId: ({ columnApi, data, level, parentKeys = [] }) => {
const groupColumns = columnApi.getRowGroupColumns();
if (groupColumns.length > level) {
const field = groupColumns[level].getColDef().field;
return [...parentKeys, data[field]].join('-');
}
return [...parentKeys, data.athlete, data.year];
},
Very recently a new type of column was add to smartsheet : multi drop down :
Is there any solution to create such column using the api ?
Is a new version of the api planned ?
As of Oct 1, you can actually create a column that supports the new multi-dropdown feature. The documentation is a little behind.
If you don't yet have a column, you'll have to Add a column first.
Once you have a columnId, you can send an Update Column request and specify "type" as "MULTI_PICKLIST".
To retrieve the correct type when you do a GET /sheets/{sheetId} or GET /{columnId}, you have to use a query parameter of ?level=3&include=objectValue.
It is possible to create a Dropdown (multi select) column via the API!
To briefly address the TEXT_NUMBER issue, this type is used for backwards-compatibility. If you are unaware of the ?level=2&include=objectValue suffix, the response will return a TEXT_NUMBER column type to avoid breaking any existing clients that aren't set up to handle the new column type.
In the following examples the double brace variables represent your targets:
{{environment}} is something like https://api.smartsheet.com/2.0/
{{sheetId}} is a sheet Id in the form 6264126827992742
{{columnId}} is the Id of your primary column in the form 2641268279927426
{{columnId2}} is the Id of your multi picklist column in the form 6412682799274262
To add a column with a MULTI_PICKLIST type to an existing sheet:
POST: {{environment}}/sheets/{{sheetId}}/columns/
{
"title": "I'm a new multi picklist column",
"type":"MULTI_PICKLIST",
"index": 1,
"options": ["opt1","opt2","opt3"]
}
To create a column on a brand new sheet, this example will create a sheet with a primary column, a MULTI_PICKLIST column, and then add a row with some data.
Then it will get the sheet using level 2 to avoid the backwards compatibility TEXT_NUMBER type.
To create a sheet with a MULTI_PICKLIST column:
POST: {{environment}}/sheets
{
"name":"API PL Sheet",
"columns":
[
{
"title":"My primary Column",
"primary":true,
"type":"TEXT_NUMBER"
},
{
"title":"My multi select column",
"type":"MULTI_PICKLIST",
"options":["options","in","this","form"]
}
]
}
To add a row on this sheet:
POST: {{environment}}/sheets/{{sheetId}}/rows?include=objectValue
[
{
"toTop": true,
"cells":
[
{
"columnId":{{columnId}},
"value": "1"
},
{
"columnId":{{columnId2}},
"objectValue":
{
"objectType":"MULTI_PICKLIST",
"values":["in", "form"]
}
}
]
}
]
To view the sheet with the MULTI_PICKLIST objectValue:
GET: {{environment}}/sheets/{{sheetId}}?level=2&include=objectValue
If you do not include the ?level=2&include=objectValue suffix then the JSON response will have columns that appear as though they are TEXT_NUMBER types.
For one final note, different endpoint groups require different levels. They are as follows:
GET Cell History is level 2
GET Sheets is level 2
GET Row is level 2
GET Column is level 2
POST Sort is level 2
GET Sights (dashboards) is level 3
GET reports is level 3
I've got checkboxes and selects where label is different to its value.
In the DB the value is saved ok, however, when viewing Form Entries (and pre-submit form data) for all the checkboxes and selects the values are displayed not labels. So I end up with not so informative IDs rather than names.
Is there a way to display labels instead of values in the Form Entries screen?
I came across your question while looking to do the same thing. I have a field called Account Type that stores the account type ID as the value. In the entries list I want to show the account type name, not the ID.
Here's the solution:
In your theme's functions.php file add the following filter:
add_filter( 'gform_entries_column_filter', 'modify_entry_view', 10, 5 );
You'll find the documentation for it here: https://docs.gravityforms.com/gform_entries_column_filter/
Then add the function code:
function modify_entry_view( $value, $form_id, $field_id, $entry, $query_string ){
//- Check the field ID to make sure you only change that one
if( $field_id == 14 ){
return 'modified value';
};
return $value;
}
In my case I'm using a custom field that I created called account_type that prepopulates a select menu with choices corresponding to each of the account types in our system. I used the following call to check the field type instead of checking based on field id since the id will change from form to form:
if( RGFormsModel::get_field( $form_id, $field_id )->type == 'account_type' ){
You could do the same thing but use the label property instead of type, like:
if( RGFormsModel::get_field( $form_id, $field_id )->label == 'Field Label' ){
In my case the value saved is a term id from a custom taxonomy I set up called account_type, so I simply use:
return get_term_by( 'id', $value, 'account_type' )->name;
to replace the account id with the account name.
FYI: The process is the same for the entry detail, use the filter documented here: https://docs.gravityforms.com/gform_entry_field_value/
I am trying to create a trigger in APEX, when an custom textfield of an custom sObject gets updated with products (means, when new products get insert or existing one get deleted).
How can I compare in APEX the Trigger.Old values with the Trigger? New values of this field in order to start the Trigger.
It would look something like this:
Trigger NameOfTrigger on CustomSObject__c (after update){
/*there is already an existing list of products that get insert into the custom textfield (probably as Strings)
*/
List <String> textList = new List <String> ();
/*PseudoCode: if the textfield got updated/has changed, copy from every entry of this textfield (entry = product name as a string) and copy fieldX into another sObject
*/
if(CustomSObject.field(OldValues) != CustomSObject.field(NewValues)){
for (String product : textList){
//Trigger e.g. copy the values of a certain field of p and paste them in another sObject
}
Could somebody help me with the syntax?
You can utilize inbuilt Trigger.new and Trigger.old to get the latest and old values of any record. These lists can be used to achieve what you're looking for.
Sample example would be:
Trigger NameOfTrigger on CustomSObject__c (after update){
for(CustomSObject__c customObject : Trigger.new) {
// get old record
CustomSObject__c oldCustomObject = Trigger.oldMap.get(customObject.Id);
// compare old and new values of a particular field
if(customObject.fieldName != oldCustomObject.fieldName){
//Trigger e.g. copy the values of a certain field of p and paste them in another sObject
}
}
}
See documentation of Trigger.new & Trigger.old
This may be a basic question, but it's my first, so please be kind :-).
I have a sap.m.table with two models, one model with transaction data (trxModel) and another model that is used to display a sap.m.select list (reasonCodeModel). The table model is set to trxModel.
The selected value key from the dropdown needs to update a value (ReasonCodeID) in the trxModel when a value from the reason code list is selected.
I can retrieve the selected key in the change event as so
var selKey = evt.getParameter("selectedItem").getKey();
Is there a simple way to find the trxModel relevant model path from the table row Select list value I've just modified? Or is it possible to bind the ReasonCodeID from the trxModel to the ReasonCodeID field in the reasonCodeModel?
Just an extra piece of info, The current row is selected and is accessible
var selItem = dtlTable.getSelectedItem();
2nd question and I guess could be kind of related, is there a way of getting the table model path based on the selected item (highlighted row) of the table? And vice a versa?
More details on Select & Table binding.
var tabTemplate = new sap.m.ColumnListItem(
{
::
new sap.m.Select(
"idReasonCodeSelect",
{
enabled : false,
change : function(evt) {
oS4View.getController().changeReasonCodeSel(evt);
}
}
),
Bind the resource code Select to the Table
// bind the reason codes to the reason code model
sap.ui.getCore().byId("idReasonCodeSelect").setModel(
oReasonCodeModel);
sap.ui.getCore().byId("idReasonCodeSelect").bindAggregation("items", "/results",
new sap.ui.core.Item({
key : "{ReasCodeID}",
text : "{ReasCodeDesc}"
}));
Per Qualiture comment, how do I bind the Select key to the table model ReasonCodeID value?
I found an approach to tackle the first part of my question above
From the change function on the Select, I can find the path of the table model using the following.
var path = evt.getSource().getParent().getBindingContext().sPath;
2nd Update:
On the selectionChange event on the table, there's a couple of options to find the associated model path or model content.
// find the model path
oModelPath = selItem.getBindingContext().getPath();
// model values
oItem = oEvent.getParameter("listItem").getBindingContext().getObject();
So my only remaining issue, While I loop through the table model results (trxModel) and I want the Select List (using setSelectedKey) to reflect the ReasonCodeID value in the trxModel.