18 August, 2025

Script to unapply the invoice on Credit Memo - Oracle EBS

 set serveroutput on;
declare
    l_api_version               CONSTANT NUMBER:=1;
    l_init_msg_list             CONSTANT VARCHAR2(1):=FND_API.g_false;
    l_commit                    CONSTANT VARCHAR2(1):=FND_API.g_false;
    l_acctd_amount_applied_from ar_receivable_applications_all.acctd_amount_applied_from%TYPE;
    l_acctd_amount_applied_to   ar_receivable_applications_all.acctd_amount_applied_to%TYPE;
    l_cm_app_rec                AR_CM_API_PUB.cm_app_rec_type;
  v_cm_unapp_rec            AR_CM_API_PUB.CM_UNAPP_REC_TYPE;
    g_request_id                NUMBER:=Fnd_Global.conc_request_id;
    l_msg_count                 NUMBER;
    l_msg_data                  VARCHAR2(2500);
    v_msg_data                  VARCHAR2(4000);
    v_process_status                VARCHAR2(2500);
    l_out_rec_application_id    NUMBER;
--     v_process                   VARCHAR2(1):='Y';
    l_return_status             VARCHAR2(1);
    l_gl_status                 VARCHAR2(50):=NULL;
    v_accrual_cnt               NUMBER:=0;
    v_accrual_cm_cnt            NUMBER:=0;
    v_apply_amt                 NUMBER:=0;
    v_accu_amt                  NUMBER:=0;
    v_acm_amt                   NUMBER:=0;
    v_request_id                NUMBER;
    l_boolean                   BOOLEAN;
    v_xml_layout                BOOLEAN;
    l_phase                     VARCHAR2(200);
    l_dev_phase                 VARCHAR2(200);
    l_dev_status                VARCHAR2(200);
    l_message                   VARCHAR2(4000):=NULL;
    l_status                    VARCHAR2(200);
    v_print_report              NUMBER;
v_rec_present NUMBER :=0;
    g_gl_date                   DATE;
    
CURSOR get_inv_cur IS
<write your cursor to get details for invoice >
    
    CURSOR get_accrualCM_cur IS
    
<write your cursor to get details for invoice >
 
BEGIN
   dbms_output.put_line('-------------- Process Begins -------------------');
    v_print_report := 0;
  
  
    Mo_global.init('AR');
    Mo_global.set_policy_context('S',23424); --23424
    Fnd_Global.apps_initialize( 158939,59346,222); -- patch 


    FOR rec_inv IN get_inv_cur LOOP
      /*  Fnd_Global.apps_initialize( 157894, 52189, 222 );*/
        v_process_status :=NULL;
        v_msg_data   :=NULL;
       dbms_output.put_line('running for Actual Invoice : '||rec_inv.inv_trx_num);
            
                FOR rec_acc_cm IN get_CM_cur(
                                                   rec_inv.inv_trx_num,
                                                   rec_inv.cust_acct_id
                                  )LOOP
                    v_cm_unapp_rec.cm_customer_trx_id       := rec_acc_cm.customer_trx_id;
v_cm_unapp_rec.inv_customer_trx_id  := rec_acc.customer_trx_id;
v_cm_unapp_rec.reversal_gl_date     := rec_acc_cm.gl_date;
 
                   /* --API Variables
                        l_cm_app_rec.cm_customer_trx_id          :=rec_cm.customer_trx_id;
                        l_cm_app_rec.cm_trx_number               :=rec_cm.CM_trx_num; -- Credit Memo Number
                        l_cm_app_rec.inv_customer_trx_id         :=rec_inv.customer_trx_id;
                        l_cm_app_rec.inv_trx_number              :=rec_inv.accrual_trx_num; --  Invoice Number
                        l_cm_app_rec.installment                 :=NULL;
                        l_cm_app_rec.applied_payment_schedule_id :=NULL;
                        l_cm_app_rec.amount_applied              :=v_apply_amt;
                        l_cm_app_rec.apply_date                  :=g_gl_date;
                        l_cm_app_rec.gl_date                     :=g_gl_date ;--rec_cm.gl_date;
                        l_cm_app_rec.show_closed_invoices        :='Y';
                        l_cm_app_rec.comments                    :='Showtime: Applied Accrual CM to accrual invoice ' ;
                        l_cm_app_rec.called_from                 :=NULL;

                    --Calling API
                        ar_cm_api_pub.apply_on_account(
                                                      p_api_version=>l_api_version,
                                                      p_init_msg_list=>l_init_msg_list,
                                                      p_commit=>l_commit,
                                                      p_cm_app_rec=>l_cm_app_rec,
                                                      x_return_status=>l_return_status,
                                                      x_msg_count=>l_msg_count,
                                                      x_msg_data=>l_msg_data,
                                                      x_out_rec_application_id=>l_out_rec_application_id,
                                                      x_acctd_amount_applied_from=>l_acctd_amount_applied_from,
                                                      x_acctd_amount_applied_to=>l_acctd_amount_applied_to
                        );
*/
  ar_cm_api_pub.unapply_on_account(
                  p_api_version                => 1.0
                 ,p_init_msg_list              => FND_API.G_FALSE
                 ,p_commit                     => FND_API.G_FALSE
                 ,p_cm_unapp_rec               => v_cm_unapp_rec
                 ,x_return_status              => l_return_status
                 ,x_msg_count                  => l_msg_count
                 ,x_msg_data                   => l_msg_data);

                COMMIT;
                        v_msg_data := l_msg_data;
                        IF NVL(l_return_status,'****')='S' THEN
                           dbms_output.put_line('Success for : '||rec_cm.CM_trx_num ||' Amt Applied: ' ||v_apply_amt);
                            v_process_status :='SUCCESS';
                            v_msg_data   :=NULL;
                            v_print_report := v_print_report +1;
                        ELSE
                            IF l_msg_count=1 THEN
                               dbms_output.put_line(v_msg_data);
                            ELSIF l_msg_count>1 THEN
                                FOR i IN 1..l_msg_count LOOP
                                    v_msg_data:=v_msg_data
                                                ||substr(
                                                        fnd_msg_pub.get(p_encoded=>fnd_api.g_false),
                                                        1,
                                                        1500
                                                  );
                                END LOOP;
                               dbms_output.put_line(v_msg_data);
                            END IF;
                                v_process_status := 'ERROR: '||v_msg_data;
                               dbms_output.put_line('Failure for: '||rec_cm.CM_trx_num || ' error msg: '|| v_msg_data);
                            COMMIT;
                        END IF; -- l_return_status = 'S' condition
                END LOOP; -- cursor for  CM loop
    END LOOP;-- cursor for inv loop
   dbms_output.put_line('--------------  Process Completed -------------------');
   
EXCEPTION
    WHEN OTHERS THEN
       dbms_output.put_line('Error for CM '||SQLERRM);
END ;


Query to get TCS DFF Information - Oracle EBS

 SELECT
    ffv.descriptive_flexfield_name    "DFF Name",
    ffv.application_table_name        "Table Name",
    ffv.title                         "Title",
    ap.application_name               "Application",
    ffc.descriptive_flex_context_code "Context Code",
    ffc.descriptive_flex_context_name "Context Name",
    ffc.description                   "Context Desc",
    ffc.enabled_flag                  "Context Enable Flag",
    att.column_seq_num                "Segment Number",
    att.form_left_prompt              "Segment Name",
    att.application_column_name       "Column",
    fvs.flex_value_set_name           "Value Set",
    att.display_flag                  "Displayed",
    att.enabled_flag                  "Enabled",
    att.required_flag                 "Required"
FROM
    apps.fnd_descriptive_flexs_vl    ffv,
    apps.fnd_descr_flex_contexts_vl  ffc,
    apps.fnd_descr_flex_col_usage_vl att,
    apps.fnd_flex_value_sets         fvs,
    apps.fnd_application_vl          ap
WHERE
        ffv.descriptive_flexfield_name = att.descriptive_flexfield_name
    AND ap.application_id = ffv.application_id
    AND ffv.descriptive_flexfield_name = ffc.descriptive_flexfield_name
    AND ffv.application_id = ffc.application_id
    AND ffc.descriptive_flex_context_code = att.descriptive_flex_context_code
    AND fvs.flex_value_set_id (+) = att.flex_value_set_id
    AND ffv.title IN ( 'Customer Information', 'Party Site Information', 'Party Information', 'Address Information', 'Site Use Information'
    )
    --AND att.form_left_prompt LIKE 'give TITLE NAME'
ORDER BY
    ffv.title,
    ffc.descriptive_flex_context_code,
    att.column_seq_num

Assign responsibility to user based on program responsibility

 DECLARE
   lv_user_name        VARCHAR2 (20) := 'XXUSER';
   --lv_req_resp_key     VARCHAR2 (50) := 'APPLICATION_DEVELOPER';
   lv_description      VARCHAR2 (100) := 'Adding Responsibility to user for report testing';
   lv_req_resp_name    VARCHAR2 (200);
   lv_appl_shrt_name   VARCHAR2 (20);
   lv_appl_name        VARCHAR2 (50);
   lv_resp_key         VARCHAR2 (50);
  
BEGIN

for c_cur in (

Select RESPONSIBILITY_KEY lv_req_resp_key, 
(select application_short_name  from fnd_application_vl fav where fr.application_id = fav.application_id) lv_appl_shrt_name
From apps.fnd_Responsibility fr,
apps.fnd_responsibility_tl frt,
apps.fnd_request_groups frg,
apps.fnd_request_group_units frgu,
apps.fnd_concurrent_programs_tl fcpt
Where upper(fcpt.user_concurrent_program_name) like upper('%Aged Trial Balance with Payments%')
and request_group_name = 'XX_AR_INQ_REPORTS'
and fcpt.concurrent_program_id = frgu.request_unit_id
and frgu.request_group_id = frg.request_group_id
and frg.request_group_id = fr.request_group_id
and fr.responsibility_id = frt.responsibility_id
Order By 2
      )

      loop
   fnd_user_pkg.addresp (username         => lv_user_name,
                         resp_app         => c_cur.lv_appl_shrt_name,
                         resp_key         => c_cur.lv_req_resp_key,
                         security_group   => 'STANDARD',
                         description      => lv_description,
                         start_date       => SYSDATE,
                         end_date         => NULL
                                              );
   COMMIT;
  end loop;
   DBMS_OUTPUT.put_line ('The responsibility ' || lv_req_resp_name || ' is added to the user ' || lv_user_name);
  
EXCEPTION
   WHEN OTHERS THEN
      DBMS_OUTPUT.put_line ('Responsibility IS NOT added due to ' || SQLCODE || '; ' || SUBSTR (SQLERRM, 1, 250));
      ROLLBACK;
END;