Scheduled job to submit a catalog item if password last reset was 75 days ago

Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 04:17 PM
I need to submit the catalog item if the password last reset was 75 days ago and set the Due date on RITM to 15 days (+90 days from the date on u_password_last_reset field) from the catalog item submission date.
Below are the conditions I need to check
1. Table u_user_ad_account
2. Record with name = xyz.acc (sys_id = 8gb9c08597704610769b36bc0153af46)
3. u_password_last_reset is -75 days from today.
4. Submit the catalog item (sys_id = 694d78a787e25047abs589970cbb3432)
I tried the below scheduled job script but it isn't working, could someone help
// Scheduled job script to submit a catalog item for vss.gen
// Retrieve the relevant record from u_cmdb_ci_user_ad_admin_account
var tableName = 'u_user_ad_account';
var recordSysID = '8gb9c08597704610769b36bc0153af46';
var gr = new GlideRecord(tableName);
if (gr.get(recordSysID)) {
// Get the value of u_password_last_reset
var passwordLastReset = gr.u_password_last_reset;
// Calculate the dates in relation to the current date
var currentDate = new GlideDateTime(); // Get the current date and time
var submissionDate = new GlideDateTime(passwordLastReset);
submissionDate.addDaysLocalTime(75);
var dueDate = new GlideDateTime(passwordLastReset);
dueDate.addDaysLocalTime(90);
// Check if the submission date is 75 days before today
if (submissionDate.onOrBefore(currentDate)) {
// Submit the catalog item
var serviceAccountName = 'xyz.acc';
var cart = new Cart();
var item = cart.addItem('694d78a787e25047abs589970cbb3432'); //sys_id of the catalog item
cart.setVariable(item, 'service_account_name', serviceAccountName); // Use serviceAccountName instead of recordSysID
cart.setVariable(item, 'due_date', dueDate.getDisplayValue()); // Use getDisplayValue() to format the date
var rc = cart.placeOrder(); //this launches the catalog item, and creates a request object.
// Call a function immediately to update the RITM
updateRITM(rc.sys_id, serviceAccountName, dueDate);
}
}
function updateRITM(req, serviceAccountName, dueDate) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', req); //req is what we passed from the previous function. the sys_id of the request.
ritm.query();
while (ritm.next()) {
ritm.due_date = dueDate.getDisplayValue(); // Use getDisplayValue() to format the date
ritm.assignment_group = 'd54d78a787e25047abs589k30cbr0932';
ritm.short_description = 'Submit catalog item for xyz.acc';
ritm.description = 'Routine reset of xyz.acc password';
ritm.u_service_account_name = serviceAccountName;
ritm.update();
}
}
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 04:25 PM
Have tried adding logs?
Any errors?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2024 03:23 AM
@Neel Patel - I don't see any errors in the logs.