We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Want to add "Upload" Ui action in custom table for the list view

MahendraG233225
Tera Contributor

I have created a custom table in which i want a "Upload" ui action so give me proper script, my table name is "branch master upload"

4 REPLIES 4

rohansargar
Mega Guru

Hello @MahendraG233225,

 

Create Upload UI action from System Definition > UI Action

Use this script to upload.

function onClick() {
  // Example: Redirect to a custom file upload page for this record
  var recordSysId = g_form.getUniqueValue();
  var tableName = g_form.getTableName();

  // Redirect to a custom UI Page (you must create it)
  var url = '/your_custom_upload_page.do?sys_id=' + recordSysId;
  window.open(url, '_blank');  // or use '_self' to open in same tab
}

 

If my response marked please mark it as correct,

Best regards,

Rohan

 

Not working when i'm clicking on the "Upload" Ui action

Code For UI Action :-

function onClickUpload() {
var ga = new GlideAjax('BranchMasterUploadUtils');
ga.addParam('sysparm_name', 'uploadFile');
ga.addParam('sysparm_record_id', g_form.getUniqueValue());
ga.getXMLAnswer(function(response) {
var result = response.responseXML.documentElement.getAttribute("answer");
if (result == 'success') {
gsftSubmit(null, g_form.getFormElement(), 'refresh'); // optional
alert("Upload successful.");
} else {
alert("Upload failed: " + result);
}
});
}

 

Code for Script include :- 

var BranchMasterUploadUtils = Class.create();
BranchMasterUploadUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

uploadFile: function() {
var recordId = this.getParameter('sysparm_record_id');
if (!recordId) return "No Record ID";

// Example logic – you can customize to read attachments, update fields, etc.
var gr = new GlideRecord('branch_master_upload');
if (gr.get(recordId)) {
// Sample business logic
gr.u_status = 'Uploaded'; // Assume a status field exists
gr.update();
return "success";
}
return "Record not found";
}

});

Not working