- 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
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
08-13-2025 08:20 PM
Hope you are doing good.
Did my reply answer your question?
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
08-13-2025 09:52 PM
Hi @Ankur Bawiskar
Thank you for responding!
The script is still not working as expected as 'colum1' is coming as empty.
gs.log('Ankita_del colum1' + colum1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 09:56 PM
My assumption was that your earlier logic is already working.
I just shared the enhance logic.
You should debug what's the actual issue.
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