I want to attach a document for a particular item. While attaching I have to check whether the item already has an active(External) document of document type I am attaching.
If the item already has an active document then I have to throw an error.
if(docuTypeId)
{
while select TypeId,Restriction from docuRef
where docuRef.TypeId == docuTypeId &&
docuRef.Restriction == DocuRestriction::External &&
docuRef.RecId
{
throw error("Already Exist");
}
}
In the DocuAction class - NewArgs Method. It works fine for an item . But if i add document for some other item it also throws an error stating that the type already exist because it checks the Docuref table on whole. So i dont know how to mention it for a particular item alone . Cos i couldnt able get the RefRecId field in docuref table.
You also have to check RefTableId and RefRecId in your select (in this case it would be EcoRedProduct)
You don’t need a while select, check for the existence of single record(use firstonly).
You can also have your code in \Data Dictionary\Tables\DocuRef\Methods\validateWrite
I tried writing the code in validate write method. Its working fine, But I got anther problem. When i try to update an external document I couldn’t able to update it as it check for the code and throws the same error.
Please check the following image for better clarification,