Monday, December 8, 2025

SQL query to Extract Contact Points from Bill-To Site, Using AR Transaction in Oracle Fusion Cloud (AR)

 

Introduction

In Oracle Fusion AR, reporting requirements often go beyond basic transaction data. Business users frequently need the complete customer communication hierarchy, especially the Bill-To contact person, their email address, site use attributes, and any assigned responsibility roles such as BILL_TO.

However, extracting this information is not straightforward because Oracle Fusion Customer Data Management (CDM) stores customer, site, role, and communication details across multiple HZ (Trading Community Architecture) tables.

This guide provides a single, end-to-end SQL query that starts with an AR Transaction (Invoice) and traces the entire path down to:

  • Invoice details
  • Customer account and site information
  • Bill-To site use
  • Contact role assignments
  • Communication points such as email
  • Responsibility types (e.g., BILL_TO)

Why This SQL Is Important

Most organizations need this extract to support:

  • Customer communication audits
  • Invoice delivery validation
  • Billing compliance
  • Master data troubleshooting
  • AR reporting automation

Because contacts in Oracle Fusion are stored through relationships, roles, and contact points, you must traverse many joins to get the final result.

This post gives you a ready-to-use, optimized SQL that performs all these joins correctly—with ranking logic to prioritize BILL_TO contacts.


Data Hierarchy Explained

Here’s the full path the SQL follows:

1. AR Transaction

  • RA_CUSTOMER_TRX_ALL → Invoice Number, Date
  • Links to Bill-To Site Use

2. Customer Account & Site

  • HZ_CUST_SITE_USES_ALL
  • HZ_CUST_ACCT_SITES_ALL
  • HZ_CUST_ACCOUNTS
  • HZ_PARTY_SITES

3. Contact Role Mapping

  • HZ_CUST_ACCOUNT_ROLES → role assignment at site
  • HZ_ROLE_RESPONSIBILITY → BILL_TO / SHIP_TO duties

4. Contact Person

  • HZ_RELATIONSHIPS → maps account to person
  • HZ_PARTIES → person profile
  • HZ_CONTACT_POINTS → email/phone/etc.

This ensures a reliable, hierarchy-accurate extraction.


Complete SQL: Contact Point Extraction from Bill-To Site

WITH raw_contact_data
     AS (SELECT RCTA.trx_number         AS INVOICE_NUMBER,
                RCTA.trx_date           AS INVOICE_DATE,
                -- Customer and Site
                HCA.account_number      AS CUSTOMER_ACCOUNT_NUMBER,
                HPS.party_site_number   AS SITE_NUMBER,
                HCSU.site_use_code      AS SITE_USE_CODE,
                -- Contact Details
                HP_PER.party_name       AS CONTACT_NAME,
                HCP.email_address       AS CONTACT_EMAIL_ADDRESS,
                HRR.responsibility_type AS RESPONSIBILITY_CHECK,
                -- If 'BILL_TO' exists, give it Rank 1. Else give Rank 2.
                Dense_rank()
                  over (
                    PARTITION BY RCTA.trx_number
                    ORDER BY CASE WHEN HRR.responsibility_type = 'BILL_TO' THEN
                  1
                  ELSE 2
                  END ASC
                  )                     AS rec_rank
         FROM   fusion.ra_customer_trx_all RCTA
                -- 1. Core Joins (Invoice to Account/Site)
                join fusion.hz_cust_site_uses_all HCSU
                  ON HCSU.site_use_id = RCTA.bill_to_site_use_id
                join fusion.hz_cust_acct_sites_all HCAS
                  ON HCAS.cust_acct_site_id = HCSU.cust_acct_site_id
                join fusion.hz_cust_accounts HCA
                  ON HCA.cust_account_id = HCAS.cust_account_id
                join fusion.hz_party_sites HPS
                  ON HPS.party_site_id = HCAS.party_site_id
                -- 2. Contact Roles
                left join fusion.hz_cust_account_roles HCAR
                       ON HCAR.cust_acct_site_id = HCAS.cust_acct_site_id
                          AND HCAR.role_type = 'CONTACT'
                          AND HCAR.status = 'A'
                -- 3. Responsibility Type (BILL_TO)
                left join fusion.hz_role_responsibility HRR
                       ON HRR.cust_account_role_id = HCAR.cust_account_role_id
                          AND HRR.responsibility_type = 'BILL_TO'
                          AND HRR.status_flag = 'A'
                -- 4. Links to Person
                left join fusion.hz_relationships HR
                       ON HR.relationship_id = HCAR.relationship_id
                          AND HR.subject_type = 'ORGANIZATION'
                          AND HR.object_type = 'PERSON'
                          AND HR.status = 'A'
                left join fusion.hz_parties HP_PER
                       ON HP_PER.party_id = HR.object_id
                          AND HP_PER.status = 'A'
                -- 5. Email Contact Point
                left join fusion.hz_contact_points HCP
                       ON HCP.owner_table_id = HP_PER.party_id
                          AND HCP.owner_table_name = 'HZ_PARTIES'
                          AND HCP.contact_point_type = 'EMAIL'
                          AND HCP.status = 'A'
                          AND HCP.primary_flag = 'Y'
         WHERE  RCTA.trx_number = '120251107182')

SELECT DISTINCT invoice_number,
                invoice_date,
                customer_account_number,
                site_number,
                site_use_code,
                contact_name,
                contact_email_address,
                responsibility_check
FROM   raw_contact_data
WHERE  rec_rank = 1  


How the SQL Works (Breakdown)

1. Ranking Logic

The DENSE_RANK() ensures that BILL_TO contacts appear first, falling back to any contact if none are defined.

2. Bi-Directional Relationship Handling

Oracle Fusion stores contacts using HZ_RELATIONSHIPS:

  • Organization (account) → Person (contact)

The SQL handles both sides cleanly.

3. Site-Level Role Extraction

HZ_ROLE_RESPONSIBILITY is filtered to active BILL_TO responsibility types.

4. Communication Point Precision

Only the primary email is extracted to avoid duplicates.










Friday, October 10, 2025

Oracle Fusion Dunning Letter Delivery Details Report SQL — Fetch Dunning letter name, delivery status etc against a Account, Site, and Contact Information for AR Collections

Description

Learn how to build a Dunning Letter Delivery Details Report in Oracle Fusion using SQL. This query retrieves customer account and site details, collector names, and site contact information (email, phone) for efficient AR collection follow-ups.

Introduction

In Oracle Fusion Cloud Financials, the Dunning Letter Delivery Details Report is an essential tool used by Accounts Receivable (AR) and Collection teams to track the status of Dunning Letters — reminders sent to customers for overdue invoices.

However, the standard seeded report often lacks complete contact-level details such as email addresses and phone numbers associated with each customer site. Without this, collection agents must manually look up contacts, making follow-up inefficient.

This article provides a custom SQL query that enriches the Dunning Letter Delivery Details Report by fetching customer account numbers, site properties, dunning details, and primary contact information directly from Oracle Fusion HZ and AR tables.


Business Use Case

The Dunning Letter Delivery Details Report helps AR departments to:

  • Track when and how dunning letters were sent (email, print, or manual).

  • Verify delivery status (e.g., “Sent”, “Failed”, “In Process”).

  • Identify customer contacts responsible for communication at the site level.

  • Align collectors with specific accounts and sites for better accountability.

This customized SQL extends the functionality of the standard report by integrating HZ (Customer Master), IEX (Collections), and AR (Payments) tables — offering a single unified view.


Oracle SQL – Dunning Letter Delivery Details Report

Below is the full SQL query that fetches Dunning Letter details, Account and Site information, and primary contact email/phone for each site.


SELECT hca.account_number             AS ACCOUNT_NUMBER,
       hp.party_name                  AS PARTY_NAME,
       hca.account_name               AS ACCOUNT_NAME,
       hro.NAME                       AS BU_NAME,
       hps.party_site_number          AS BILL_TO_SITE_NUMBER,
       hps.party_site_name            AS PROPERTY_NAME,
       rsua.location                  AS LOCATION_SITE_USE_IDENTIFIER,
       Sum(aps.amount_due_original)   AS TOTAL_AMOUNT_ORIGINAL,
       d.amount_due_remaining,
       d.letter_name,
       d.status,
       d.contact_destination,
       d.delivery_status              AS EMAIL_DELIVERY_STATUS,
       d.created_by,
       d.creation_date,
       d.dunning_method,
       coll_acc.NAME                  AS Account_Collector_Name,
       coll_site.NAME                 AS Site_Collector_Name,
       hp_contact.person_first_name
       || ' '
       || hp_contact.person_last_name AS CONTACT_FULL_NAME,
       hcp_email.email_address        AS CONTACT_EMAIL_ADDRESS,
       hcp_phone.phone_number         AS CONTACT_PHONE_NUMBER
FROM   iex_dunnings d
       JOIN hz_cust_accounts hca
         ON d.cust_account_id = hca.cust_account_id
       JOIN hr_organization_units_f_tl hro
         ON d.bu_id = hro.organization_id
       LEFT JOIN hz_cust_site_uses_all rsua
              ON d.site_use_id = rsua.site_use_id
       LEFT JOIN hz_cust_acct_sites_all hcasa
              ON hcasa.cust_acct_site_id = rsua.cust_acct_site_id
       LEFT JOIN hz_party_sites hps
              ON hcasa.party_site_id = hps.party_site_id
       LEFT JOIN iex_dunning_transactions dt
              ON dt.dunning_id = d.dunning_id
       LEFT JOIN ar_payment_schedules_all aps
              ON aps.customer_trx_id = dt.cust_trx_id
       LEFT JOIN hz_customer_profiles_f prof_acc
              ON prof_acc.cust_account_id = d.cust_account_id
                 AND prof_acc.site_use_id IS NULL
                 AND Trunc(sysdate) BETWEEN Trunc(prof_acc.effective_start_date)
                                            AND
                                            Trunc(prof_acc.effective_end_date)
       LEFT JOIN ar_collectors coll_acc
              ON prof_acc.collector_id = coll_acc.collector_id
       LEFT JOIN hz_customer_profiles_f prof_site
              ON prof_site.cust_account_id = d.cust_account_id
                 AND prof_site.site_use_id = d.site_use_id
       LEFT JOIN ar_collectors coll_site
              ON prof_site.collector_id = coll_site.collector_id
       LEFT JOIN hz_cust_account_roles hcr
              ON hcr.cust_acct_site_id = hcasa.cust_acct_site_id
                 AND hcr.status = 'A'
                 AND hcr.role_type = 'CONTACT'
       LEFT JOIN hz_relationships hr
              ON hr.relationship_id = hcr.relationship_id
                 AND hr.relationship_type = 'CONTACT'
                 AND hr.directional_flag = 'F'
       LEFT JOIN hz_parties hp_contact
              ON hr.subject_id = hp_contact.party_id
       LEFT JOIN hz_contact_points hcp_email
              ON hcp_email.owner_table_name = 'HZ_PARTIES'
                 AND hcp_email.owner_table_id = hp_contact.party_id
                 AND hcp_email.contact_point_type = 'EMAIL'
                 AND hcp_email.primary_flag = 'Y'
       LEFT JOIN hz_contact_points hcp_phone
              ON hcp_phone.owner_table_name = 'HZ_PARTIES'
                 AND hcp_phone.owner_table_id = hp_contact.party_id
                 AND hcp_phone.contact_point_type = 'PHONE'
                 AND hcp_phone.primary_flag = 'Y'
WHERE  1 = 1
       --and d.creation_date > sysdate - 200
       AND hca.account_number = :account_number
       AND hps.party_site_number = :party_site_number
GROUP  BY hca.account_number,
          hca.account_name,
          hro.NAME,
          hps.party_site_number,
          hps.party_site_name,
          rsua.location,
          d.amount_due_remaining,
          d.letter_name,
          d.status,
          d.contact_destination,
          d.delivery_status,
          d.created_by,
          d.creation_date,
          d.dunning_method,
          coll_acc.NAME,
          coll_site.NAME,
          hp_contact.person_first_name,
          hp_contact.person_last_name,
          hcp_email.email_address,
          hcp_phone.phone_number
ORDER  BY d.creation_date DESC

SQL query to Extract Contact Points from Bill-To Site, Using AR Transaction in Oracle Fusion Cloud (AR)

  Introduction In Oracle Fusion AR, reporting requirements often go beyond basic transaction data. Business users frequently need the comp...