Create task record via scheduled job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 12:25 PM
Hi everyone,
I have a requirement to create a task record when the current date match with a date in a sys_user record 14 days before. So If curren date is 07.02.23 and the date in the sys user record is 20.02.23 than a task should be created with some values.
My idea is to create a scheduled script which runs every day and check the current date and the date in the sys_user table from every record via Gliderecord and create a task record with a second gliderecord via if condition if its matches.
Is there maybe a smarter way to achieve my requirement?
Thanks for any input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 12:45 PM
Could do it in a flow as well. You may want to use a range, since it's probably using a date/time, in the GR. You can certainly do it in a scheduled job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 01:37 AM
var todayDate = new GlideDate();
gs.info(today.getValue());
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if (gr.next()) {
var eintrittsDatum = gr.getValue('u_hcm_eintrittsdatum');
var typ = gr.getValue('u_hcm_typ');
var userID = gr.getValue('user_name');
}
if (todayDate >= eintrittsDatum.getNumericValue() - (14 * 24 * 60 * 60 * 1000)) {
var newRecord = new GlideRecord("universal_request");
newRecord.initialize();
newRecord.short_description = + "AD-Account anlegen - " + userID;
newRecord.description = + "Art: " + typ;
newRecord.insert();
} else {
// Art: ==> HCM-Typ
}
thanks for reply. Her is my code so far in the scheduled job, but its not working. Its dont create a record. What is my problem here? How could I test my code best way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 02:01 AM
Hi @JohnDF ,
In cmdb_health_result table,for HW class, if the created date is prior to the updated date then I need to send 1 email to that respective CI's CI group manager.
(Frequency of that mail is twice in a month e.g 1st & 15th of the month)
How I achieve this via schedule job? Kindly assist me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 05:21 AM
Add logs to verify what it's doing.
This will only ever result in one record.
I was thinking you'd do like (psuedo/shorthand), basically get date of now+14 days, then query to get list of users, then create new records from the results.
figure out the date or date/time (because we don't know what u_hcm_eintrittsdatum is. today+14 days
var newDate = (what's stated above)
query sys_user
add query for u_hcm_eintrittsdatum == new Date. You may have to use start/end method depending on the type of field it is.
while gr.next() (will contain steps of all user accounts expiring in 14 days.
{
within here you create new records.
}