The 1C:Enterprise developers forum

#1
People who like this: 0 Yes / 0 No
Interested
Rating: 11
Joined: Nov 10, 2011
Company: 1A Software e.U

I need to write a sting in a form field, but I get an error message "object is ReadOnly" - "Objekt ist schreibgeschützt"

Code
&AtClient
Procedure CashDiscountOnChange(Item)
   If Object.CashDiscount < 0 Then
       Items.CashDiscountText.ReadOnly = False;
       Items.CashDiscountText = "minus " + Object.CashDiscount*-1 + " % ";
   EndIf;   
EndProcedure


For example if Cash Discount = -5%, so I need a text "minus 5 %".

What's wrong in my code?

Thanks in advance

Edited: Lioudmila Nemtseva - Sep 26, 2013 03:50 PM
 
#2
People who like this: 0 Yes / 0 No
Just came
Rating: 0
Joined: Mar 23, 2013
Company: 1C Company

Hey Lioudmila! is CashDiscountText a form attribute? If it is, you can set it directly by doing:

CashDiscountText = "minus " + Object.CashDiscount*-1 + " % ";

 
#3
People who like this: 0 Yes / 0 No
Interested
Rating: 11
Joined: Nov 10, 2011
Company: 1A Software e.U

Hi Bernard,

Thank you for your reply. Yes, it is a document form attribute. But it also doesn't work this way. In this case I don't get any error, but the field is not changed.

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

If your field is a decoration without reference to the object attribute, use the following script:

Code
Items.CashDiscountText.Title = "minus " + Object.CashDiscount*-1 + " % "

1C Company support team
 
#5
People who like this: 0 Yes / 0 No
Interested
Rating: 11
Joined: Nov 10, 2011
Company: 1A Software e.U

Thanks, Sergey! But in this case nothing happens. No error, but the attribute is not changed.

 
#6
People who like this: 0 Yes / 0 No
Interested
Rating: 11
Joined: Nov 10, 2011
Company: 1A Software e.U

I have found it out! I deleted data attribute and (Bernard, you were right!) created a textfield with data path CashDiscountText1.

Code
&AtClient
Procedure CashDiscount1OnChange(Item)
   If Object.CashDiscount1 < 0 Then
       CashDiscountText1 = "abzüglich " + Object.CashDiscount1*-1 + " % " + "nachlass";
       
   EndIf;   
EndProcedure


I have 4 CashDiscounts 1 to 4.

Thank you all guys!  :)

 
#7
People who like this: 0 Yes / 0 No
Timofey Bugaevsky
Guest

Joined:
Company:

Please note that strings that are displayed to user should be localized, so use NStr function for that. Also for substitution into string for localization reasons please use function of 1C:Subsystems Library, here is an example:

Code
MessageText = NStr("en = 'Failed to generate the %1 on the base of %2.'");
MessageText = StringFunctionsClientServer.SubstituteParametersInString(MessageText,
                       Metadata.FindByType(TypeOf(Ref)).Presentation(), String(Value)); 

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