Show Spreadsheet Binding with a Script

Posts: 72
Don't need help with a full script, just need to know how to return a spreadsheet binding. Basically, the script would say "If driver ID is found in spreadsheet, then display their team name according to the spreadsheet, if not then display their club." I'm stuck on the displaying spreadsheet data in a script part.
Posts: 72
Alright complete 180 on this, I have a different problem now

I got a script working that either displays data from a spreadsheet or returns a normal data output if the driver is not in the sheet. I have the return set to "result.Entity.CurrentDriver.Name", but need it to output just the first name. Changing to "result.Entity.CurrentDriver.FirstName" gives me the following error:

'IDriver' does not contain a definition for 'FirstName' and no accessible extension method 'FirstName' accepting a first argument of type 'IDriver' could be found (are you missing a directive or an assembly reference?)
Posts: 785
iRacing doesn't give us the first name. Determining what is someones first name is a surprisingly difficult problem and will not be correct all the time. For the "firstname" binding, we simply look for the first space in the name and return everything before that.
result.Entity.CurrentDriver.Name.Split(' ').FirstOrDefault()
Posts: 72
Getting a similar error when I put that as the return value:

'string[]' does not contain a definition for 'FirstOrDefault' and no accessible extension method 'FirstOrDefault' accepting a first argument of type 'string[]' could be found (are you missing a directive or an assembly reference?)

I just used copy and paste to throw it into the script, here's the full script:
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;

namespace Scripts
{
public class test : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
IEntitySessionResult result = (IEntitySessionResult) value;

Spreadsheet sheet = item.Theme.Spreadsheets.Find("TESTING CSV.csv");

var check = sheet.FindRow(result.Entity.CurrentDriver.Id.ToString());
var row = sheet.FindRow(result.Entity.CurrentDriver.Id.ToString());

if (check != null)
{
var name = row[1];
return name;
}
return result.Entity.CurrentDriver.Name.Split(' ').FirstOrDefault();
}
}
}
Posts: 785
That error almost always means you need a "using" statement at the top (there is a post about this with more details).
In this case I think you need this one:
using System.Linq;
Posts: 72
That worked, thank you!