Hi there!
Before helping you, I’d like to understand what task you’re trying to solve with this line of code:
| Code |
|---|
Presentation = StrReplace(fullDescr, "/", ", "); |
So, you have products whose descriptions contain slashes, and when displaying these products to the user, you want to dynamically replace the slashes with commas. That makes sense.
My question is — wouldn’t it be simpler to add another attribute to the Products catalog, where you store a transformed version of the description, already “cleaned” of slashes? You could fill this attribute, for example, when saving the object, using the same code:
| Code |
|---|
Presentation = StrReplace(fullDescr, "/", ", "); |
If I had to solve a similar task, that’s exactly how I would do it.
Why? Let me show you.
Let’s say we have a catalog with three products (Picture 1).
And we’ve written the following code in the Manager Module of the catalog (Picture 2)
Now, turn on debugging and open the “Product” catalog interactively in 1C.
You’ll easily notice that the PresentationGetProcessing procedure is called for every catalog item that the system displays in the list form.
If there are only three products, that won’t affect performance much.
But what if there are hundreds or thousands?
In that case, each time the form is reopened, the system will execute this text replacement for every product — and eventually, that can negatively impact system performance.
Whenever possible, it’s better to avoid writing code that could potentially slow down the system.
Now, let’s get back to the error you’re encountering.
First, one more recommendation: it is strongly NOT recommended to use the direct deletion mode in 1C (Picture 3)
It’s much better, if you really need to delete something, to use the “Toggle deletion mark” mode instead. Why? It’s simple.
When you delete directly, 1C just removes the object from the database without checking whether there are any references to it elsewhere.
For example, let’s say we’ve created an Invoice document that includes the product “Product 2” in its table part.
Then, we go and directly delete that product from the catalog. As a result, we’ll end up with something like this (Picture 4).
You can see that the Invoice document still holds a reference to the product, but the product itself has been physically deleted from the database table.
To avoid this kind of situation, it’s recommended to use “Toggle deletion mark.”
When using that mode, the object isn’t immediately deleted — it’s only marked for deletion. The actual deletion happens later, when a service routine is run. (Picture 5)
At that time, the 1C platform checks referential integrity — meaning, if the product you’re trying to delete is still referenced in any documents, the platform won’t allow its removal.
Now, back to your specific error 🙂
Set a breakpoint, start 1C in dialog mode, open the “Products” catalog, and try to directly delete one product.
You’ll easily notice that when deleting, the PresentationGetProcessing procedure is called twice.
In the first call, the object hasn’t yet been deleted from the database — it still has references. (Picture 6)
Press F5, and you’ll hit the second call. (Picture 7)
This time, the object has already been deleted from the database (on the server), but in the catalog’s list form, it still remains visible — and naturally, any attempt to access Data.Ref at that point will throw an error!
So what’s the recommendation?
It depends on your use case.
I would personally add another attribute and avoid direct deletion altogether.
But if you still want to go with your current approach, you could do something like this:
| Code |
|---|
Procedure PresentationGetProcessing(Data, Presentation, StandardProcessing)
StandardProcessing = False;
Try
fullDescr = Data.Ref.FullDescr();
Presentation = StrReplace(fullDescr, "/", ", ");
Except
EndTry;
EndProcedure |
However, this still wouldn’t be the best solution! 🙂