As a part of the asset conversion/creation process we might have created a wrong asset or the data might be wrong and you want to delete the asset after conversion. Following is a useful code to delete Fixed Assets programmatically:
Note: You can delete assets only when you are adding and their accounts are not yet processed in subledger accounting. Also, this an anonymous PL/SQL block, a function/procedure can be easily created using this code
l_asset_hdr_rec fa_api_types.asset_hdr_rec_type;
l_return_status VARCHAR2 (1);
l_mesg_count NUMBER := 0;
l_mesg_len NUMBER;
l_mesg VARCHAR2 (4000);
BEGIN
DBMS_OUTPUT.ENABLE (1000000);
fa_srvr_msg.init_server_message;
-- asset header info
l_asset_hdr_rec.asset_id := &asset_id;
l_asset_hdr_rec.book_type_code := '&book';
fa_deletion_pub.do_delete
(p_api_version => 1.0,
p_init_msg_list => fnd_api.g_false,
p_commit => fnd_api.g_false,
p_validation_level => fnd_api.g_valid_level_full,
x_return_status => l_return_status,
x_msg_count => l_mesg_count,
x_msg_data => l_mesg,
p_calling_fn => NULL,
px_asset_hdr_rec => l_asset_hdr_rec
);
l_mesg_count := fnd_msg_pub.count_msg;
IF l_mesg_count > 0
THEN
l_mesg :=
CHR (10) || SUBSTR (fnd_msg_pub.get (fnd_msg_pub.g_first, fnd_api.g_false),1,250);
DBMS_OUTPUT.put_line (l_mesg);
FOR i IN 1 .. (l_mesg_count - 1)
LOOP
l_mesg :=
SUBSTR (fnd_msg_pub.get (fnd_msg_pub.g_next, fnd_api.g_false),1,250);
DBMS_OUTPUT.put_line (l_mesg);
END LOOP;
fnd_msg_pub.delete_msg ();
END IF;
IF (l_return_status <> fnd_api.g_ret_sts_success)
THEN
DBMS_OUTPUT.put_line ('FAILURE');
--Oracle Assets Deletion API L-5
ELSE
DBMS_OUTPUT.put_line ('SUCCESS');
DBMS_OUTPUT.put_line ('ASSET_ID' || TO_CHAR (l_asset_hdr_rec.asset_id));
DBMS_OUTPUT.put_line ('BOOK: ' || l_asset_hdr_rec.book_type_code);
END IF;
END;
Note:- We can only delete assets uploaded/added in current open period. We cannot delete new assets with depreciation processed or assets added in previous periods. If depreciation is processed on assets in current period then role back depreciation and delete latest uploaded assets.
ORA-01403: no data found
ReplyDeleteError: function fa_util_pvt.get_asset_desc_rec returned failure
Error i am getting while running the blocks........
DeleteThank you for nice useful script