How to get doc name?

ill create sales order and the doc name is “SO-00006” and i submit it. then ill make sales invoice. the problem is, on my print format on sales invoice i want to get sales order number “SO-00006” into my sales invoice but it doesnt work please help me. thanks! this is what happen see this picture below.

THIS IS MY SALES ORDER

THIS IS MY SALES INVOICE

Sales Order reference is in Sales Invoice Item table.

Seems like it is your custom print format .So you can fetch it from table as below,

{{ doc.items[0].sales_order }}

thankyou thanks a lot very helpful @Sangram