- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 03:07 AM
Hi All,
I have a MRVS with 3 fields i.e. Employee ID, First Name and Last Name.
It gets populated from Excel attachment, I want to validate the Employee ID.
Employee ID is a reference field, I am trying to validate employee_id's with User table and if valid then it should be populated in MRVS along with First and Last name.
I am trying the logic in SCRIPT INCLUDE below, please suggest.
Script include :
OnChange Client Script on Attachment field :
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 03:27 AM
-> push the details in object only when USER found
update script include function as this
getXLData: function() {
var arrObj = [];
var file_id = this.getParameter('sysparam_attSysId');
var req_type = this.getParameter('sysparam_req_type');
var row = '';
var att = new GlideSysAttachment().getContentStream(file_id);
var parser = new sn_impex.GlideExcelParser();
parser.parse(att);
var headers = parser.getColumnHeaders();
// var list_sheet_name = parser.getSheetNames();
// gs.log("MapExcelDatatoMRVS Sheet Names " + list_sheet_name.join(", ") + checktabresult + list_sheet_name.length);
while (parser.next()) {
var obj = {};
var idobj = {};
row = parser.getRow();
var colum1 = parser.getColum();
if (req_type == 'Modify' || req_type == 'Add' || req_type == 'Change / Move') {
gs.log('Ankita_del colum1' + colum1);
//Validate EMP ID
colum1 = colum1.trim();
var idnew = colum1.split(',');
var delarray = [];
for (var i = 0; i < idnew.length; i++) {
var emp_id = new GlideRecord('sys_user');
emp_id.addQuery('employee_number', idnew[i]);
emp_id.addQuery('active', true);
emp_id.query();
if (emp_id.next()) {
obj.employee_id = emp_id.getUniqueValue();
obj.firstname = emp_id.getValue('first_name');
obj.lastname = emp_id.getValue('last_name');
}
}
}
if (req_type == 'Delete') {
obj.mediabar_genesys_application_username_to_be_delete_disable = row[headers[0]];
// obj.accountnumber11 = row[headers[1]];
}
arrObj.push(obj);
}
return JSON.stringify(arrObj);
},
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
hi @Ankur Bawiskar
this onchange client script is for the field.
I want to trigger onchange catalog client script on the catalog item variable.
Some how for the attachment variable in the catalog item - script is not getting triggered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
please post a new question and share all the details there, also tag me there
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
hi @Ankur Bawiskar
This requirement applies to catalog item variables, specifically an attachment variable.
When a user uploads an Excel file into this attachment variable:
The system must validate the contents of the Excel file against the User ID of the logged-in user.
If even a single invalid or incorrect entry is detected in the file, the user must not be allowed to submit the catalog request.
The catalog form should display the list of incorrect entries clearly to the user, so they can review and correct the file before resubmitting.
