01 August, 2025

Sample Script API Hz_Party_Contact_V2pub.create_org_contact

  set serveroutput on;
declare
x_org_contact_id                NUMBER;
  x_party_rel_id                  NUMBER;
  x_org_party_id                  NUMBER;
  x_org_party_number              VARCHAR2(2000);
   x_return_status                 VARCHAR2 (10);
  x_msg_count                     NUMBER;
  x_msg_data                      VARCHAR2 (20000);
l_msg_index_out                 NUMBER;
   l_error_message                 VARCHAR2 (20000)                 := NULL;
  p_org_contact_rec               Hz_Party_Contact_V2pub.org_contact_rec_type;
BEGIN
p_org_contact_rec.party_site_id := 8787727;
p_org_contact_rec.party_rel_rec.subject_id := 10572128;
p_org_contact_rec.created_by_module := 'TCA_V2_API';
p_org_contact_rec.party_rel_rec.subject_type := 'PERSON';
p_org_contact_rec.party_rel_rec.subject_table_name := 'HZ_PARTIES';
p_org_contact_rec.party_rel_rec.object_id := 10122562;
p_org_contact_rec.party_rel_rec.object_type := 'ORGANIZATION';
p_org_contact_rec.party_rel_rec.object_table_name := 'HZ_PARTIES';
p_org_contact_rec.party_rel_rec.relationship_code := 'CONTACT_OF';
p_org_contact_rec.party_rel_rec.relationship_type := 'CONTACT';
p_org_contact_rec.party_rel_rec.status := 'A';
p_org_contact_rec.party_rel_rec.start_date := SYSDATE;
apps.Fnd_Msg_Pub.delete_msg (NULL);
apps.Fnd_Msg_Pub.initialize ();
Hz_Party_Contact_V2pub.create_org_contact
(p_init_msg_list        => Fnd_Api.g_true,
  p_org_contact_rec      => p_org_contact_rec,
  x_return_status        => x_return_status,
  x_msg_count            => x_msg_count,
  x_msg_data             => x_msg_data,
  x_org_contact_id       => x_org_contact_id,
  x_party_rel_id         => x_party_rel_id,
  x_party_id             => x_org_party_id,
  x_party_number         => x_org_party_number
);
IF x_return_status != 'S'
THEN
l_error_message := NULL;
   
DBMS_OUTPUT.put_line ('Creation of Org Contact got failed:'||x_msg_data);
  
FOR i IN 1 .. x_msg_count
LOOP
   apps.Fnd_Msg_Pub.get (p_msg_index          => i,
p_encoded            => Fnd_Api.g_false,
p_data               => x_msg_data,
p_msg_index_out      => l_msg_index_out
);
   IF l_error_message IS NULL
   THEN
  l_error_message := SUBSTR (x_msg_data, 1, 250);
   ELSE
  l_error_message :=
   l_error_message || ' /' || SUBSTR (x_msg_data, 1, 250);
   END IF;
   DBMS_OUTPUT.put_line ('Error: '||l_error_message);
END LOOP;
   else
   DBMS_OUTPUT.PUT_LINE('Creation of Org Contat is Successful ');
DBMS_OUTPUT.PUT_LINE('Output information ....');   
DBMS_OUTPUT.PUT_LINE('x_org_contact_id = '||x_org_contact_id);
DBMS_OUTPUT.PUT_LINE('x_party_rel_id = '||x_party_rel_id);
DBMS_OUTPUT.PUT_LINE('x_org_party_id = '||x_org_party_id);
DBMS_OUTPUT.PUT_LINE('x_org_party_number = '||x_org_party_number);

END IF;
EXCEPTION
  WHEN OTHERS
  THEN
x_party_rel_id := NULL;
x_org_party_id := NULL;

  END;
  
  /*
  Output information ....
x_org_contact_id = 5969901
x_party_rel_id = 6047470
x_org_party_id = 10572137
x_org_party_number = 4934314
*/

Sample Script API hz_cust_account_site_v2pub.create_cust_site_use

 
SET SERVEROUTPUT ON;
DECLARE
p_cust_site_use_rec    HZ_CUST_ACCOUNT_SITE_V2PUB.CUST_SITE_USE_REC_TYPE;
p_customer_profile_rec HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE;
x_site_use_id          NUMBER;
x_return_status        VARCHAR2(2000);
x_msg_count            NUMBER;
x_msg_data             VARCHAR2(2000);
BEGIN
-- Setting the Context --
mo_global.init('AR');
fnd_global.apps_initialize ( user_id      => 158240
                            ,resp_id      => 51117
                            ,resp_appl_id => 222);
mo_global.set_policy_context('S',101);
-- Initializing the Mandatory API parameters
p_cust_site_use_rec.cust_acct_site_id := 3670724;
p_cust_site_use_rec.site_use_code     := 'BILL_TO';
p_cust_site_use_rec.location          := '110974-30362';
p_cust_site_use_rec.created_by_module := 'CUST_INTERFACE';
p_cust_site_use_rec.primary_flag := 'Y';
p_cust_site_use_rec.orig_system_reference :='110974-30362';
DBMS_OUTPUT.PUT_LINE('Calling the API hz_cust_account_site_v2pub.create_cust_site_use');
HZ_CUST_ACCOUNT_SITE_V2PUB.CREATE_CUST_SITE_USE
                   (
                     p_init_msg_list         => FND_API.G_TRUE,
                     p_cust_site_use_rec     => p_cust_site_use_rec,
                     p_customer_profile_rec  => p_customer_profile_rec,
                     p_create_profile        => FND_API.G_TRUE,
                     p_create_profile_amt    => FND_API.G_TRUE,
                     x_site_use_id           => x_site_use_id,
                     x_return_status         => x_return_status,
                     x_msg_count             => x_msg_count,
                     x_msg_data              => x_msg_data
                          );
                         
IF  x_return_status = fnd_api.g_ret_sts_success THEN
    COMMIT;
    DBMS_OUTPUT.PUT_LINE('Creation of Customer Accnt Site use is Successful ');
    DBMS_OUTPUT.PUT_LINE('Output information ....');   
    DBMS_OUTPUT.PUT_LINE('Site Use Id = '||x_site_use_id);
    DBMS_OUTPUT.PUT_LINE('Site Use    = '||p_cust_site_use_rec.site_use_code);     
ELSE
    DBMS_OUTPUT.put_line ('Creation of Customer Accnt Site use got failed:'||x_msg_data);
    ROLLBACK;
    FOR i IN 1 .. x_msg_count
    LOOP
      x_msg_data := fnd_msg_pub.get( p_msg_index => i, p_encoded => 'F');
      dbms_output.put_line( i|| ') '|| x_msg_data);
    END LOOP;
END IF;
DBMS_OUTPUT.PUT_LINE('Completion of API');
END;
/

24 August, 2022

API to apply Credit Memo to refund activity

    The following sample code will use the existing credit memo, and will create a credit memo application to issue a refund using AR_CM_APPLICATION_PUB.ACTIVITY_APPLICATION.

--  Turn on DBMS_OUTPUT to display messages on screen
set serveroutput on size 1000000
--  Declaration section
DECLARE
   l_dummy varchar2(240);
   l_customer_trx_id ra_customer_trx.customer_trx_id%type;
   l_msg_count number := 0;
   l_msg_data varchar2(20000) := null;
   l_return_status varchar2(1);
   l_application_ref_type varchar2(30);
   l_application_ref_id number;
   l_application_ref_num VARCHAR2(30);
   l_receivable_application_id NUMBER;



BEGIN
   --  Set the applications and organization context
   fnd_global.apps_initialize(1318,50559,222,0);
   mo_global.init('AR');
   mo_global.set_policy_context('S',204);
   --  provide CUSTOMER_TRX_ID of the credit memo
   l_customer_trx_id := 527710;
   --  call ACTIVITY_APPLICATION
   AR_CM_APPLICATION_PUB.ACTIVITY_APPLICATION(
     P_API_VERSION => 1.0,
     P_INIT_MSG_LIST => FND_API.G_TRUE,
     P_COMMIT => FND_API.G_FALSE,
     P_VALIDATION_LEVEL => FND_API.G_VALID_LEVEL_FULL,
     p_customer_trx_id => l_customer_trx_id,
     p_amount_applied => 200,
     p_applied_payment_schedule_id => -8,
     p_receivables_trx_id => 2579,
     p_apply_date => to_date('04/20/2011','MM/DD/YYYY'),
     p_apply_gl_date => to_date('04/20/2011','MM/DD/YYYY'),
     p_application_ref_type => l_application_ref_type,
     p_application_ref_id => l_application_ref_id,
     p_application_ref_num => l_application_ref_num,
     p_receivable_application_id => l_application_ref_id,
     X_RETURN_STATUS => l_return_status,
     X_MSG_COUNT => l_msg_count,
     X_MSG_DATA => l_msg_data);
   --  return information about the status of the API run
   FND_MSG_PUB.count_and_get (
   p_encoded => FND_API.g_false,
   p_count => l_msg_count,
   p_data => l_msg_data );
   dbms_output.put_line('Return Status ==> '||l_return_status);
   dbms_output.put_line('l_msg_count ==> '||l_msg_count);

   -- display messages from the message stack
   FOR I IN 1..L_MSG_COUNT LOOP
       DBMS_OUTPUT.PUT_LINE(SUBSTR(FND_MSG_PUB.GET(P_MSG_INDEX => I, P_ENCODED => 'F'), 1, 254));
   END LOOP;
   IF l_return_status <> 'S' THEN
      NULL;
   ELSE
      dbms_output.put_line(' CM Application_id = '|| l_application_ref_id );
      -- You can issue a COMMIT; at this point if you want to save the created credit memo to the database
   END IF;
EXCEPTION
WHEN OTHERS THEN
   dbms_output.put_line('exception error!');
   dbms_output.put_line(substr(sqlerrm, 1, 80));
   fnd_message.retrieve(l_dummy);
   dbms_output.put_line(l_dummy);
END;

How to create Credit Memo: API to create Credit Memo