the Name of the record to be populated to the name of the file in the Image field when submitted

Community Alums
Not applicable

When I create a new user  record, I upload a file to the Image field, upon upload or upon submit, the name of the user record should be the name of the image I've uploaded. However, we will strip the file type from the name. (example1.png = example1)

 

4 REPLIES 4

Sanjay191
Tera Sage

Hello @Community Alums 
  

  • Fetch an attachment name from a target record (using its sys_id).

  • Update the user_name field in the Users table (sys_user) with the name of that attachment.

  • Use Business Rule (server-side) and Client Script  to achieve this.

    1. Attachments in ServiceNow are stored in the sys_attachment table.

    2. Each attachment is linked to a record (target record) via the table_sys_id.

    3. Using a Business Rule, you can fetch attachments related to a record.

    4. You can then update a field like user_name on the sys_user table using a script.

    5.  You can  trim or split you attachment file name according you requirement.
      if anything else please let me know 

      If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
      Thank You

 

 

Community Alums
Not applicable

I tried ,but thing is servicenow stores image name as image in the attachment table if filed type is image.

ex:image name ex01 but in servicenow attachment table stores as image(if we upload any image by using image type filed ,servicenow stores as image)

Yes but if you attach as attachment then you get the name of it , not on image type field that is the alternate way for it 
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You

Muhammad Salar
Giga Sage

Hello, try this in Business Rule
var attGR = new GlideRecord('sys_attachment');
attGR.addQuery('table_name', 'sys_user');
attGR.addQuery('table_sys_id', current.sys_id);
attGR.orderByDesc('sys_created_on');
attGR.query();

if (attGR.next()) {
var oldFileName = attGR.file_name.toString();
var extension = oldFileName.substring(oldFileName.lastIndexOf('.'));
var newFileName = current.user_name + extension;


attGR.file_name = newFileName;
attGR.update();
}