Adding UD field to Grid view on Time Phase

Hi Epiusers community,

I’m following the following method to add a UD field to the Time Phase grid by repurposing an unused column and adjusting it with a post-processing directive, which seems like the easiest method for my first-time custom code work with limited C# knowledge.

Add UD fields from other BO in grid - #16 by Christian_Pouchoulen

However, I am getting the error messages
The name ‘DB’ does not exist in the current context
The name ‘ttTimePhas’ does not exist in the current context

Below are my codes

foreach (var ttTimePs in (from row in ttTimePhas select row))
{
    var dbJobName = (from row in DB.JobHead
      where row.Company == Session.CompanyID &&
            row.JobNum == ttTimePs.JobNum 
            select row).FirstOrDefault();

    if (dbJobName != null)
    {
        // Set the value of ttTimePs.PrintMe to the JobName_c field from JobHead
        ttTimePs.PrintMe = dbJobName.JobName_c;
    }
    else
    {
        // Handle the case where there is no matching JobHead record
        ttTimePs.PrintMe = ""; 
    }
}

Need some guidance here. Thank you in advance.

Db and you dont have tt tables in method. You will need use ds.XTableName

@ttm.chester.tan Welcome. I had a routine that did this since 2012 and this gave me a reason to clean it up. In custom code you can right click to see what parameters are available. Sometimes tt, ds or in this case result. Do not return a whole row if you only need one field. If you need more fields then add a new{} and put your fields in the braces. If you only need to know if something exists there is an .Any rather than a .Select. I noticed when checking syntax that PrintMe is a bool, so I used SourceFile which is the field I hijacked.

image
then TimePhas
image

foreach (var ttTimePs in result.TimePhas)
{
    var dbJobName = Db.JobHead.Where(row => row.Company == Session.CompanyID && row.JobNum == ttTimePs.JobNum).Select(s => s.JobName_c).FirstOrDefault();

    if (dbJobName != null)
    {
        // Set the value of ttTimePs.PrintMe to the JobName_c field from JobHead
        ttTimePs.SourceFile = dbJobName;
    }
    else
    {
        // Handle the case where there is no matching JobHead record
        ttTimePs.SourceFile = ""; 
    }
}