How to create a calendar entry using workflows?

ragz
Tera Expert

I am working on service catalog , Once user request an item in the catalog and it has go through the approval process .

Once the request is approved then a calendar has to create about schedule to pick up in the users calendar and the technician calendar .

How to achieve this ?

1 ACCEPTED SOLUTION

Hi ragz,

In your Workflow, after the approval, I would create a "Run Script" activity that we will create the calendar events in.

The calendar events exist in the following table: user_calendar_event

So we'll create two new records on that table using the GlideRecord API in our Run Script activity. I'm assuming the User, Technician, and Start and End Date of the appointment are variables in your Catalog Item? Let's pretend like they are for this example and call the variables "user", "technician", "start_date", and "end_date".

The code would look something like this then, but you'll have to replace the variable names and any of the other fields you'd like to change to fit your process.

var user = new GlideRecord('user_calendar_event');
user.newRecord();
user.user = current.variables.user;
user.name = 'Technician Appointment';
user.type = 'task_work';
user.task = current.getUniqueValue();
user.start_date_time = current.variables.start_date;
user.end_date_time = current.variables.end_date;
user.insert();

var tech = new GlideRecord('user_calendar_event');
tech.newRecord();
tech.user = current.variables.technician;
tech.name = 'Technician Appointment';
tech.type = 'task_work';
tech.task = current.getUniqueValue();
tech.start_date_time = current.variables.start_date;
tech.end_date_time = current.variables.end_date;
tech.insert();

You can read more about GlideRecord API here: GlideRecord API

Thanks!

Josh

View solution in original post

6 REPLIES 6

Josh Virelli
Tera Guru

Hi ragz,

Are you asking to send out a Calendar invite to both user's Outlook calendars?

If so you can do that through a notification, here's the documentation from ServiceNow:

Calendar Integration

If that's not what you're looking for can you explain a little further?

Thanks

Josh

 

Hi Josh, 

 

Thanks for the reply . I need to integrate with outlook as well as  put the entry in Service now calendar entry also .

 

You reply covers the first part . I need how to insert the entry into service now calendar when Technician and user can see the appointments ?

Thanks in Advance

Hi ragz,

In your Workflow, after the approval, I would create a "Run Script" activity that we will create the calendar events in.

The calendar events exist in the following table: user_calendar_event

So we'll create two new records on that table using the GlideRecord API in our Run Script activity. I'm assuming the User, Technician, and Start and End Date of the appointment are variables in your Catalog Item? Let's pretend like they are for this example and call the variables "user", "technician", "start_date", and "end_date".

The code would look something like this then, but you'll have to replace the variable names and any of the other fields you'd like to change to fit your process.

var user = new GlideRecord('user_calendar_event');
user.newRecord();
user.user = current.variables.user;
user.name = 'Technician Appointment';
user.type = 'task_work';
user.task = current.getUniqueValue();
user.start_date_time = current.variables.start_date;
user.end_date_time = current.variables.end_date;
user.insert();

var tech = new GlideRecord('user_calendar_event');
tech.newRecord();
tech.user = current.variables.technician;
tech.name = 'Technician Appointment';
tech.type = 'task_work';
tech.task = current.getUniqueValue();
tech.start_date_time = current.variables.start_date;
tech.end_date_time = current.variables.end_date;
tech.insert();

You can read more about GlideRecord API here: GlideRecord API

Thanks!

Josh

You could actually make this code a little better, I broke it out into two different blocks just to show what I was doing.

But make your function once and then pass in the user, like so:

function createCalendarEvent(user){
var cal = new GlideRecord('user_calendar_event');
cal.newRecord();
cal.user = user;
cal.name = 'Technician Appointment';
cal.type = 'task_work';
cal.task = current.getUniqueValue();
cal.start_date_time = current.variables.start_date;
cal.end_date_time = current.variables.end_date;
cal.insert();
}

//Call the function twice with the user and technician
createCalendarEvent(current.variables.user);
createCalendarEvent(current.variables.technician);

 

Always try to not repeat yourself when coding 🙂

Best of luck!
Josh