Fetching Sales Invoices in Journal Entry (Credit Note)

We have written a custom script in Journal Entry as follows:

//to fetch sales invoice ID from Sales Invoice to Journal Entry Accounts table.

However, we are unable to see any data in the Journal Entry table in order to adjust payment against sales invoices.

Please let us know where the problem lies.