how to fetch catalog item variable values from 'sc_cart_item' table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 04:33 AM
I have a requirement where HR team imports an excel sheet with a 'Department' column. They do this through a Catalog Item. On the catalog item they select a 'department' variable. Now the requirement is that excel sheet Column and the Variable selected should be SAME. If not, the RITM should not get created.
I tried to achieve this using Before insert Business Rule on sc_cart_item. But I'm unable to fetch variable value from this table.
var deptList = current.variables.department.getDisplayValue(); // not working
this is not helping.
Would be great if I could get some suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 01:58 AM
I could achieve the validation part using 'sc_req_item' Table. And upon failure of the validations I am aborting the creation of RITM. Now the issue is how can I delete REQUEST (REQ) that's getting created. Don't want any record getting created on failure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 02:09 AM
how did you achieve this? please share the logic
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 05:33 AM
Before Insert on sc_req_item table:
var deptList = current.variables.select_business.getDisplayValue(); // variable value
var arrDept = deptList.split(', ');
var attach = new GlideRecord('sys_attachment');
attach.orderByDesc('sys_created_on');
attach.setLimit(1);
attach.addQuery('table_name', 'sc_cart_item');
attach.addQuery('sys_created_by', gs.getUserName());
attach.addEncodedQuery('sys_created_onRELATIVEGT@minute@ago@1');
attach.addQuery('file_name', 'CONTAINS', '.xls');
attach.query();
if (attach.next()) {
var attachment = new GlideSysAttachment();var attachmentStream = attachment.getContentStream(attach.sys_id.toString());
var parser = new sn_impex.GlideExcelParser();
parser.parse(attachmentStream);
var headers = parser.getColumnHeaders();
var rowNumber = 0;
if (headers.indexOf('Department_L1') >= 0) {
var flag = false;
while (parser.next() && flag == false) {