Upload Profile Photo In User Table

Gowthami Senthi
Kilo Expert

Hi All,

Whenever the photo has been uploaded in user record, I want to validate whether the uploaded image size is more than 200 KB. If its more than 200 KB we need to show an alert message saying "Max attach size is 200 KB". I want to display this message in the page which will appear while clicking the "Click to add.."" in User record.

Kindly let me know the possible ways to achieve this.

Thanks in advance

8 REPLIES 8

Hi Slava,



Thankyou so much for your reply.....



I have tried the same which you mentioned above but even after displaying the message the photo is getting updated in the profile. My requirement is to restrict the image upload which is more than 200KB and the old photo should remain in the profile after the error message populated.


Hi Aj



Above business rule looks good.


Please use this code: current.setAbortAction(true) in above BR to abort the action.


Hi,



Please change the script as below:



    var limit_kb = '200';


      if (current.size_bytes > limit_kb * 1024) {


              gs.addErrorMessage('Image size exceeds the limit of ' + limit_kb + ' KB. Try a different one.');


              current.setAbortAction(true);


      }


Gowthami Senthi
Kilo Expert

Hi,



When I give current.setAbortAction(); expected error message appearing and its redirecting to User table but image is got updated.


When   I give current.setAbortAction(true); error message didn't appear and its redirected to User table and image got updated.



Below script is working like abort action is happening but previous image got deleted from User table. I need to abort the action but previous record should remain in user profile.



=============================


Table: Attachment [sys_attachment]


Active: true


Advanced: true


When: before


Insert: true



Filter Condition:


  Table name = ZZ_YYsys_user


  File name = photo



Script:


      var limit_kb = '200';


      if (current.size_bytes > limit_kb * 1024) {


              gs.addErrorMessage('Image size exceeds the limit of ' + limit_kb + ' KB. Try a different one.');


              current.setAbortAction();


              gs.setRedirect('/user_image.do?sysparm_sys_id='+current.table_sys_id;


      }


=============================



Here I have a doubt that we are aborting the action before inserting the record itself then how ll be the previous record is getting deleted?