Error with sn_sc.CartJS() in HRSD scope

Devika3
Tera Guru

Hi All,

We have a requirement to submit a Request from an HR ticket. Created the backend script , but it is throwing error. Can anyone please guide here.

 

var desc1 = current.rich_description.toString();
var e1 = desc1.split('Employee ID:'); 
var e2 = e1[1].split('<br>');
var eid = e2[0]; // employee id
 
var f1 = desc1.split('First Name:');
var f2 = f1[1].split('<br>');
var fn = f2[0];
 
var s1 = desc1.split('Surname:');
var s2 = s1[1].split('<br>');
var sn = s2[0];
 
var ad1 = desc1.split('Additional Information:');
var ad2 = ad1[1].split('<br>');
var ad = ad2[0];
 
var date1 = desc1.split('Termination effective date:');
var date2 = date1[1].split('<br>');
var date = date2[0];
 
 
var empno = eid;
var firstname = fn;
var lastname = sn;
//var date1 = terdate;
//var date = current.variable_pool.u_termination_effective_date;
var info = ad;
//var info = 'test';
//var date1 = new GlideDate (date);
//var terdate = date1.getByFormat("dd-MMM-yyyy");
//var gd = new GlideDate(); 
//gd.setValue(date);
//var terdate = gd.getByFormat("dd-MMM-yyyy");
var desc = '';
//gs.log('user id here ' + user);
var user  = new GlideRecord('sys_user');
user.addQuery('employee_number',empno);
user.addQuery('first_name',firstname);
user.addQuery('last_name',lastname);
user.query();
if(user.next()){
var name = user.name;
var sysid = user.sys_id;
var id = user.user_name;
var title = user.title;
var manager = user.manager.getDisplayValue();
var managerid = user.manager.user_name;
var location = user.location.getDisplayValue();
 
}
 
desc = '\n' + 'User: ' + name + '(' + id + ')' + '\n' + 'Title: ' + title + '\n' + 'Manager: ' + manager +  '(' + managerid + ')' + '\n' + 'Location: ' + location + '\n' + 'Involuntary Termination: false'+ '\n' + 'Delegate user: ' + manager +  '(' + managerid + ')' + '\n' + 'Date and Time of Termination: ' +  date + '\n' + 'Business Justification: ' + info + '\n\n' + 'This is created from the Termination of Employment Ticket : ' + current.number;
 
//gs.log('print the desc here ' + desc); 
 
 
var cart = new sn_sc.CartJS(); 
var item = 
'sysparm_id': '4061c90b69faa900bb9678765678', //sys_id of catalog item
'sysparm_requested_for' :current.opened_for,  // tries with current.opened_for.toString(), as well
'sysparm_opened_by' : current.opened_for,
'sysparm_quantity': '1', 
'variables': { 
'sys_usr' :sysid,
'sys_mgr' :'manager
'sys_invterm':'false',
'sys_termdate':'date
'business_justification':info
}, 
}; 
var cartDetails = cart.orderNow(item);
 
 
 
 
 
 
Thanks in Advance.
Devika.
 
 
 
 
 
1 ACCEPTED SOLUTION

Devika3
Tera Guru

The issue happened due to a spacing in the Employee ID, once it is removed we need to convert the sysid of the user record to string as=nd pass it through the Cart API.

View solution in original post

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

What is the error message? Please provide ALL details.

Ankur Bawiskar
Tera Patron
Tera Patron

@Devika3

CartJS is supported in scoped app

Did you debug from your side to know error is coming at which line?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Devika3_0-1704975435367.png

PFA for the error message getting

Devika3
Tera Guru

The issue happened due to a spacing in the Employee ID, once it is removed we need to convert the sysid of the user record to string as=nd pass it through the Cart API.