The 1C:Enterprise developers forum

#1
People who like this: 0 Yes / 0 No
Active user
Rating: 5
Joined: Jun 4, 2013
Company:

Hi, I'm having a problem with a program and I'm wondering if some one can help me here

It's a little bit complex so I'll start with the structure

1- I created a catalog with no attribute just description (Items)
2- an information register (ItemsInfortmationResgister) with:
a- dimension (Name) type: catalogref.items then I checked the Master check box ... by that way a reference for the information register will appear in the catalog form
b- a resource (price) type: number



and the problem is I want to make sure that if the user created one catalog he must create an information register for it and make sure the price dimension is filled as well


so I did so :

Code

&Atserver
Function  CancelTheCatalog()
f=0;
     
Query = New Query;
Query.Text = "SEL ECT * FR OM InformationRegister.ItemsInformationRegister   ";
Selection = Query.Execute().Choose();

if Selection.Count()=0 then
f=1;   
endif;
   

       

While Selection.Next() do

if not string(Selection.name)=String(Object.Description)  then
f=1;   
endif;

if string(Selection.name)=String(Object.Description) and Selection.price=0  then
f=1;

endif;
enddo;
      
return f;
                 
EndFunction                                                                                    


&AtClient
Procedure BeforeWrite(Cancel, WriteParameters)
f=CancelTheCatalog();

if f=1 then
cancel=True
endif;

EndProcedure



the catalog will never write anything as long as there is no record
in the information register related to it

but when the program run, when the user is creating a catalog and want to enter to the reference of the information register in the left the program will display the following message :

"Data has not been yet recorded
switching to "item information register" is allowed only after data is recorded
the data will be recorded"

but my code won't let it to record and the program will stuck and never work because the data won't be recorded and you can't create
an information register record without writing the catalog.


this is the problem i know it seems impossible but can someone give me another suggestion or something to avoid this struggle, I'll be so thankful because it very important to me to do this task ... and thanks in advance :)

 
#2
People who like this: 0 Yes / 0 No
Active user
1C:Professional
Rating: 8
Joined: Jun 25, 2013
Company: 1C Company

Infobase has no reference to your catalog item before you write it, therefore you can't make a record in the register.

There are many ways to solve your problem, which one you should choose depends on what you want to reach with this register. In all of them you write the item first and than make a record in the register. In the general case, let users specify the price with a special document.

And don't forget to use conditions in your queries instead of While Selection.Next() Do iterations:

Code
"
      |WHERE
      |   *****.Item = &Item
      |   AND *****.Price > 0"
"

1C Company support team
 
#3
People who like this: 0 Yes / 0 No
Active user
Rating: 5
Joined: Jun 4, 2013
Company:

Thanks for Helping

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)