Você está na página 1de 6

Debrief Completes With Error "An instance could not

be found..." (Doc ID 845551.1)


When attempting to perform a debrief on a Task the following error is generated:
An instance could not be found for the item and location information provided. Item ID:
<item_id>.
Organization ID: <org_id>.
Steps To Reproduce:
1. Create a Service Request
2. Create a Task
3. Perform a Debrief
Note the error message

Cause
The cause of the issue is invalid / incorrect data in CSI_ITEM_INSTANCES
The data should reflect the instance quantity available to transact as it was done in inventory.
The current quantity for the item is not correct so IB cannot process the transaction as it would
drive the quantity negative.
The following SQL identified the invalid / incorrect data:
select mmt.subinventory_code, mmt.transfer_subinventory, mmt.transaction_date,
mmt.transaction_id, mmt.transaction_quantity , cte.
error_text, ct.transaction_date , ct.source_transaction_date
,ciih.instance_id, cii.quantity, cii.active_end_date,
cii.inv_subinventory_name
, cii.serial_number, cii.instance_usage_code
from apps.csi_txn_errors cte, apps.mtl_material_transactions mmt, apps.
csi_transactions ct, apps.csi_item_instances_h ciih
, apps.csi_item_instances cii
where mmt.inventory_item_id = &&inventory_item_id
and (mmt.subinventory_code = '&&subinventory' or mmt.transfer_subinventory =
'&&subinventory')
and cte.inv_material_transaction_id(+) = mmt.transaction_id
and ct.inv_material_transaction_id(+) = mmt.transaction_id
and ciih.transaction_id(+) = ct.transaction_id
and cii.instance_id(+) = ciih.instance_id
order by 2

If according to the output of that query, there should be a quantity > 0 in Install Base for the item
in the sub-inventory used for the debrief, but the quantity in IB does not exist then IB is out of
synch.
The output of this query shows what IB should have available for that sub-inventory:
select instance_id, active_end_date, quantity, serial_number
from csi_item_instances
where inventory_item_id = &&inventory_item_id
and inv_subinventory_name = '&&subinventory'

The Error Correction Program in Synch mode should synchronize IB with the inventory on-hand
quantities and take care of this. But it only does that under certain restrictions (e.g. no pending
transaction errors for the item). So in case the debrief needs to go through quickly, the below
solution provides a way to create an instance in IB to make the instance available.

Solution
To implement the solution, please execute the following steps::
1. Ensure that you have taken a backup of your system before applying the recommended
solution.
2. Run the following script (in a TEST environment first):
Note that the parameters being passed (mainly for x_instance_rec) may need to be modified to be
appropriate for the item to be processed. E.g. a value for serialnumber, lot_number or locator
(inv_locator_id) may need to be passed. Currently the script is passing NULL for these two.

SET SERVEROUTPUT ON;


declare
X_INSTANCE_REC
CSI_DATASTRUCTURES_PUB.INSTANCE_REC;
X_EXT_ATTRIB_VALUES CSI_DATASTRUCTURES_PUB.EXTEND_ATTRIB_VALUES_TBL;
X_PARTY_TBL
CSI_DATASTRUCTURES_PUB.PARTY_TBL;
X_ACCOUNT_TBL
CSI_DATASTRUCTURES_PUB.PARTY_ACCOUNT_TBL;
X_PRICING_ATTRIB_TBL CSI_DATASTRUCTURES_PUB.PRICING_ATTRIBS_TBL;
X_ORG_ASSIGNMENTS_TBL CSI_DATASTRUCTURES_PUB.ORGANIZATION_UNITS_TBL;
X_ASSET_ASSIGNMENT_TBL CSI_DATASTRUCTURES_PUB.INSTANCE_ASSET_TBL;
X_TXN_REC
CSI_DATASTRUCTURES_PUB.TRANSACTION_REC;
X2_TXN_REC
CSI_DATASTRUCTURES_PUB.TRANSACTION_REC;
x_return_status
VARCHAR2(100);
x_msg_count
NUMBER;
x_msg_data
VARCHAR2(2000);
x_created_manually_flag VARCHAR2(100);
V_INSTANCE_ID
NUMBER;

P_COMMIT
VARCHAR2(5);
P2_COMMIT
VARCHAR2(5);
P_VALIDATION_LEVEL NUMBER;
P_INIT_MSG_LST
VARCHAR2(500);
V_INSTANCE_PARTY_ID
NUMBER;
V_IP_ACCOUNT_ID
NUMBER;
X_RELATIONSHIP_TBL CSI_DATASTRUCTURES_PUB.II_RELATIONSHIP_tbl;
V_RELATIONSHIP_ID
NUMBER;
V_SUCCESS
VARCHAR2(1) := 'T';
x2_return_status VARCHAR2(100);
x2_msg_count
NUMBER;
x2_msg_data
VARCHAR2(2000);
P2_VALIDATION_LEVEL NUMBER;
P2_INIT_MSG_LST
VARCHAR2(500);
l_material_transaction_id
NUMBER;
l_stage
VARCHAR2(100);
l_error
EXCEPTION;
l_transaction_error_id
NUMBER;
l_transaction_id
NUMBER;
l_error_pending
EXCEPTION;
l_trx_processed
EXCEPTION;
begin
-- ********** FOR The Instance
*****************************************************

SELECT CSI_ITEM_INSTANCES_S.NEXTVAL
INTO
V_INSTANCE_ID
FROM
sys.dual;
X_INSTANCE_REC.INSTANCE_ID
:= V_INSTANCE_ID;
X_INSTANCE_REC.INSTANCE_NUMBER := V_INSTANCE_ID;
l_stage := 'get mtl transaction data';
X_INSTANCE_REC.INVENTORY_ITEM_ID := &inventory_item_id
X_instance_rec.INV_SUBINVENTORY_NAME := '&subinventory_name';
X_INSTANCE_REC.INV_ORGANIZATION_ID = &inventory_org_id;
X_INSTANCE_REC.ACTIVE_START_DATE := to_date('01-JAN-2008','DD-MON-RRRR');
X_INSTANCE_REC.QUANTITY := &debrief_quantity;
X_INSTANCE_REC.UNIT_OF_MEASURE := '&debrief_uom';
IF X_INSTANCE_REC.QUANTITY <= 0 THEN
RAISE l_error;
END IF;
l_stage := 'get master org';

select master_organization_id
into
X_INSTANCE_REC.INV_MASTER_ORGANIZATION_ID
from MTL_PARAMETERS_VIEW
where organization_id = X_INSTANCE_REC.INV_ORGANIZATION_ID;
l_stage := 'get default status id';
select instance_status_id
into X_INSTANCE_REC.INSTANCE_STATUS_ID
from csi_instance_statuses
where name = fnd_profile.value('CSI_DEFAULT_INSTANCE_STATUS');
l_stage := 'set misc. values';
X_INSTANCE_REC.SERIAL_NUMBER
:= null; --not serialized
X_INSTANCE_REC.MFG_SERIAL_NUMBER_FLAG := 'N';
X_INSTANCE_REC.INSTANCE_USAGE_CODE
:= 'IN_INVENTORY';
X_INSTANCE_REC.ACCOUNTING_CLASS_CODE := 'INV';
X_INSTANCE_REC.CUSTOMER_VIEW_FLAG := 'N';
X_INSTANCE_REC.MERCHANT_VIEW_FLAG := NULL;
X_INSTANCE_REC.SELLABLE_FLAG
:= NULL;
X_INSTANCE_REC.LOCATION_TYPE_CODE := 'INVENTORY';
X_INSTANCE_REC.INV_LOCATOR_ID
:= null; -- in case of no locator
control
X_INSTANCE_REC.LOT_NUMBER
:= null; -- in case of no revision control
X_INSTANCE_REC.INSTALL_DATE
:= null;
X_INSTANCE_REC.CREATION_COMPLETE_FLAG := 'Y';
X_INSTANCE_REC.VERSION_LABEL
:= 'AS_CREATED';
X_INSTANCE_REC.LAST_OE_PO_NUMBER := null;
X_INSTANCE_REC.OBJECT_VERSION_NUMBER := 1;
l_stage := 'get location id';
select location_id
into X_INSTANCE_REC.LOCATION_ID
from hr_organization_units
where organization_id = X_instance_rec.INV_ORGANIZATION_ID;
-- ************* FOR PARTIES *************************************************
l_stage := 'set owner party data';
SELECT CSI_I_PARTIES_S.NEXTVAL
INTO
V_INSTANCE_PARTY_ID
FROM
sys.dual;
X_PARTY_TBL(1).INSTANCE_PARTY_ID := V_INSTANCE_PARTY_ID;
X_PARTY_TBL(1).INSTANCE_ID
:= V_INSTANCE_ID;
X_PARTY_TBL(1).PARTY_SOURCE_TABLE := 'HZ_PARTIES';

X_PARTY_TBL(1).RELATIONSHIP_TYPE_CODE := 'OWNER';
X_PARTY_TBL(1).CONTACT_FLAG
:= 'N';
X_PARTY_TBL(1).ACTIVE_START_DATE := X_INSTANCE_REC.ACTIVE_START_DATE;
X_PARTY_TBL(1).OBJECT_VERSION_NUMBER := 1;
l_stage := 'get internal party';
select internal_party_id
into X_PARTY_TBL(1).PARTY_ID
from csi_install_parameters;

-- ************************** TRANSACTION REC


*************************************
l_stage := 'set transaction data';

X_TXN_REC.TRANSACTION_DATE
:= X_INSTANCE_REC.ACTIVE_START_DATE;
X_TXN_REC.SOURCE_TRANSACTION_DATE := X_INSTANCE_REC.ACTIVE_START_DATE;
X_TXN_REC.TRANSACTION_TYPE_ID
:=1;
X_TXN_REC.OBJECT_VERSION_NUMBER
:=1;
X_TXN_REC.ATTRIBUTE15
:='created by script from note 845551.1';

-*************** API CALL


***************************************************
l_stage := 'call API';
DBMS_OUTPUT.PUT_LINE('BEFORE CREATE ITEM INSTANCE');
CSI_ITEM_INSTANCE_PUB.CREATE_ITEM_INSTANCE
(p_api_version
=> 1.0
,p_commit
=> P_COMMIT
,p_init_msg_list
=> P_INIT_MSG_LST
,p_validation_level
=> P_VALIDATION_LEVEL
,p_instance_rec
=> X_INSTANCE_REC
,p_ext_attrib_values_tbl => X_EXT_ATTRIB_VALUES
,p_party_tbl
=> X_PARTY_TBL
,p_account_tbl
=> X_ACCOUNT_TBL
,p_pricing_attrib_tbl
=> X_PRICING_ATTRIB_TBL
,p_org_assignments_tbl
=> X_ORG_ASSIGNMENTS_TBL
,p_asset_assignment_tbl => X_ASSET_ASSIGNMENT_TBL
,p_txn_rec
=> X_TXN_REC
,x_return_status
=> X_RETURN_STATUS
,x_msg_count
=> X_MSG_COUNT
,x_msg_data
=> X_MSG_DATA );
DBMS_OUTPUT.PUT_LINE('AFTER

CREATE ITEM INSTANCE');

l_stage := 'after API call';


if x_return_status != APPS.FND_API.G_RET_STS_SUCCESS then
dbms_output.put_line('Error found at stage: '||l_stage);
dbms_output.put_line(APPS.FND_MSG_PUB.Get(
p_msg_index
=> APPS.FND_MSG_PUB.G_LAST,
p_encoded
=> APPS.FND_API.G_FALSE));
V_SUCCESS := 'F';
rollback;
return;
else
dbms_output.put_line('Inserted Install base data');
dbms_output.put_line(' The instance Id is#:
' || v_instance_id);
COMMIT;
end if;
EXCEPTION
WHEN l_error then
dbms_output.put_line('
eligible transaction id');
dbms_output.put_line('
positive quantity');

Transaction quanity is <= 0 - this is not an


Make sure to use the transfer transaction with

WHEN l_error_pending THEN


dbms_output.put_line('Do not proceed !! - there is still a pending
error for this transaction with transaction_error_id: '||
l_transaction_error_id);
WHEN l_trx_processed THEN
dbms_output.put_line('Do not proceed !! - this transaction has been
processed already; IB transaction: '||l_transaction_id);
WHEN OTHERS THEN
dbms_output.put_line('Error found at stage: '||l_stage);
dbms_output.put_line('Error : '|| SQLERRM);
end;
/
commit;

3. Resubmit the debrief.