Create an AR credit notification using API
DECLARE -- 8000000063 l_dummy varchar2 (240); l_customer_trx_id percent % type; l_line_credits_flag percent % type; l_line_amount number; l_freight_amount number: = 0; character percent; character varchar2 (150 ); rochelle comments varchar2 (150); Rochelle msg_count number: = 0; Rochelle msg_data varchar2 (20000): = null; Rochelle return_status Varchar2 (1); l_request_id NUMBER; l_batch_source_name varchar2 (150) default null; cm_trx_id number; BEGIN -- c. set the applications and org context fnd_global.apps_initialize (1110,50683, 222); mo_global.init ('ar '); mo_global.set_policy_context ('s', 121); -- d. provide CUSTOMER_TRX_ID of the invoice to credit l_customer_trx_id: = 165023; l_comments: = 'demo for Create_Request API '; -- e. populate Bat Ch Source information l_batch_source_name: = 'om preference '; -- f. the presence of l_cm_lines_tbl indicates this is a LINE-LEVEL credit -- details for (1) are credits against line #1 identified by customer_trx_line_id = 824472 l_cm_lines_tbl (1 ). customer_trx_line_id: = 403228; l_cm_lines_tbl (1 ). quantity_credited: = null; l_cm_lines_tbl (1 ). price: = null; l_cm_lines_tbl (1 ). extended_amount: =-151000; -- deta Ils for (2) are credits against line #2 identified by customer_trx_line_id = 824473 -- l_cm_lines_tbl (2 ). customer_trx_line_id: = 824473; -- l_cm_lines_tbl (2 ). quantity_credited: =-2; -- l_cm_lines_tbl (2 ). price: = 2000.00; -- l_cm_lines_tbl (2 ). extended_amount: =-4000.00; -- g. call CREATE_REQUEST AR_CREDIT_MEMO_API_PUB.CREATE_REQUEST (P_API_VERSION => 1.0, P_INIT_MSG_LIST => FND_API.G_TRUE, P_COMMIT => Response, P_VALIDATION_LEVEL => response, P_CUSTOMER_TRX_ID => l_customer_trx_id, P_LINE_CREDIT_FLAG => 'y', response => 'Return ', P_CM_LINE_TBL => response, response => 'y ', p_CREDIT_METHOD_INSTALLMENTS => null, P_CREDIT_METHOD_RULES => null, P_BATCH_SOURCE_NAME => l_batch_source_name, P_ORG_ID => 121, X_REQUEST_ID => l_request_id, X_RETURN_STA TUS => l_return_status, X_MSG_COUNT => l_msg_count, X_MSG_DATA => l_msg_data); -- h. 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 ); response ('Return Status => '| l_return_status); dbms_output.put_line ('credit Memo request_id =>' | l_request_id); dbms_output.put_line ('L _ msg_co Unt => '| l_msg_count); -- I. 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 select cm_customer_trx_id into cm_trx_id from ra_cm_requests_all where request_id = l_request_id; dbms_output.put_line ('cm trx_id = '| cm_trx_id); -- You Can issue a COMMIT; at this point if you want to save the created credit memo to the database end if; exceptionwhen 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;