Solidity: Error while getting all the sold NFTs

Hey guys, I want to get all the sold NFTs (soldItems) from one contract to another but I am facing an error called: Indexed expression has to be a type, mapping or array (is function (address,uint256) view external returns (uint256)) from the below function:

function getPurchaseItem(address tokenAddress, address collectionContract) public view returns(uint256[] memory){
    return LotteryEscrow(tokenAddress).soldItems[collectionContract]; (Error) 
    }

And this is how I declared mapping in the LotteryEscrow contract:
mapping(address => uint256[]) public soldItems;
How do I solve this error?
Thank you!

You can access this variable (read and write) only inside the contract where it is declared.

But since this variable is declared public, the compiler automatically generates a function which allows accessing it (read only) from outside this contract, i.e., from other contracts, as well as from an off-chain script.

For this specific variable, the function generated by the compiler is:

function soldItems(address x) public view returns(uint256[] memory) {
    return soldItems[x];
}

Therefore, in your other contract, you should replace this:

return LotteryEscrow(tokenAddress).soldItems[collectionContract];

With this:

return LotteryEscrow(tokenAddress).soldItems(collectionContract);

Yes but if I do it like that then I am getting an error called:- Return argument type uint256 is not implicitly convertible to expected type (type of first return variable) uint256[] memory.solidity(6359)

function getSoldItems(address tokenAddress, address collectionContract) public view returns(uint256[] memory) {
return LotteryEscrow(tokenAddress).soldItems(collectionContract);
}

So perhaps the function generated by the compiler is actually:

function soldItems(address x, uint256 i) public view returns(uint256) {
    return soldItems[x][i];
}

In which case, you can simply implement that function yourself:

function soldItems(address x) public view returns(uint256[] memory) {
    return soldItems[x];
}

And if you don't need the other function, then you may as well declare that variable private.