Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > Adding Picture to ValueStorage; Form does not refresh

Forum

Search UsersRules
Adding Picture to ValueStorage; Form does not refresh
#1
Just came
Points:: 0
Joined:: Mar 7, 2016

Hi, I need some help:
I want to show a picture from a ValueStorage in a form ImageField. The problem is, that the picture is not shown in the image field after file selection and picture address assignment. Here is my code:

Code
&AtServer
Procedure SetPictureValueAtServer(StorageName, ClearPicture)
   
   ObjectValue = FormDataToValue(Object, Type("CatalogObject.Products"));
   If ClearPicture Then
      ObjectValue.PictureStorage = Undefined;
   Else
      ObjectValue.PictureStorage = New ValueStorage(GetFromTempStorage(StorageName));
   EndIf;
   ObjectValue.Write();
    
   ValueToFormData(ObjectValue, Object);
    
EndProcedure

&AtClient
Procedure PictureClick(Item, StandardProcessing)
   StorageName = "";
   FileName = ""; 
    
   If PutFile(StorageName, FileName, FileName, True, UUID) Then
      SetPictureValueAtServer(StorageName, FALSE);
   EndIf;
    
   FormPictureAddress = GetURL(Object.Ref, "PictureStorage");
EndProcedure


I have to close and reopen the form, then I see the picture. I'm using this code on open form:

Code
&AtClient
Procedure OnOpen(Cancel)

   FormPictureAddress = GetURL(Object.Ref, "PictureStorage");
   
EndProcedure


And, very strange, if I comment out GetURL in procedure OnOpen
Code
Procedure OnOpen(Cancel)
   // FormPictureAddress = GetURL(Object.Ref, "PictureStorage");
EndProcedure

I dont't see picture after reopen form (shure), but if I select now a file (procedure PicturClick runs) it only works just once! Picture is shown imediatly before this message:

By the way, how can I suppress this message?

Thanks in advance for help
Michael

Profile
#2
Active user
Points:: 0
Joined:: Jan 14, 2013

You can use code :

Code
&AtClient
Procedure PictureClick(Command)
   BeginPutFile(New NotifyDescription("ChangePictureAfterPutFile", ThisForm), , , True, UUID);   
EndProcedure

&AtClient
Procedure ChangePictureAfterPutFile(Result, Address, SelectedFileName, AdditionalParameters) Export
   If Result Then
      FormPictureAddress = Address;
   EndIf;
EndProcedure

&AtServer
Procedure OnReadAtServer(CurrentObject)
   If  CurrentObject.PictureStorage <> Undefined then
      FormPictureAddress = GetURL(CurrentObject,"PictureStorage");   
   EndIf;
EndProcedure

&AtServer
Procedure BeforeWriteAtServer(Cancel, CurrentObject, WriteParameters)
   If IsTempStorageURL(FormPictureAddress) Then
      BinaryData = GetFromTempStorage(FormPictureAddress);
      CurrentObject.PictureStorage= New ValueStorage(BinaryData, New Deflation());
   EndIf;

EndProcedure

Profile
#3
Just came
Points:: 0
Joined:: Mar 7, 2016

Hello P&A,
this works. Thanks.
Michael

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



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.