Returning value of Lookup field gives record ID, not value of lookup

Returning value of Lookup field gives record ID, not value of lookup

I am having an issue trying to populate single line fields using the user-selected value from a lookup.

The user looks up a Company Code from the lookup and this should populate the Sub-Region and Country fields using the On User Input trigger in the Company Code field.

A couple of things:

1) When I try and use a script to look up the Sub-Region and Country values from the Company Code table it is returning the Company Code lookup as Long, not the actual user-selected value String, for example "ABC". Is there any reason for this?

2) When I initiate the script it returns the Country value from the table as a numeric value, when it should return the Country name.

Here is my simple code:

  1. temp  =  Company [Company_Code == input.Company_Code.toString()];
  2. input.Sub_Region = temp.Sub_Region;
  3. input.Country = temp.Country.toString();

Currently, if I do not have the .toString function it has a type mismatch - I have tried this with toLong() on the Company_Code column but this does not return the expected results either.

Urgently need help with this, as its the basis of my whole form that it should auto-populate.