Solved! Go to Solution.
If you're setting up a query task against a layer that's in a map service you've already added to your JS API map, you can use the map service's layerInfos to loop through and match a name to an id.
Otherwise, use esri.request() to make a call to your map service endpoint. The JSON that comes back will have a layers property. Layers is an array of objects where each object corresponds to a layer in the map service. Every layer object will have an id and a name.
And thank you for the video- wish more people would do that :).
I have found videos to save time in explaining. 😄