How to create new task through script?

niveditakumari
Mega Sage

Hi,

My requirement is when any user profile is inactive in users table then it should create one task.

Can anyone help me to create task through business rule or script include?

 

Thanks In Advance!

Nivedita

1 ACCEPTED SOLUTION

Hi there,

What exactly do you mean task function seems not to be right, do you get an error? Have you directly checked the sc_task table to check if the record is created?

If I execute below code in background script it immediately works. So the GlideRecord query should be oke.

checkApp();

function checkApp() {
	createTask();
}

function createTask() {
	var task = new GlideRecord('sc_task');
	task.initialize();
	task.short_description = 'something';
	task.insert();
	
}

Please mark my answers as helpful, as they are helping you find a way to a nice solution.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

35 REPLIES 35

Hi Mark,

Can you please help with task creation script.

 

Regards,

Nivedita

I can confirm, just tested with the gslog typo: sc_task will not be created. So fix the typo or remove the logging and it should work!

Please mark my answers as helpful, as they are helping you find a way to a nice solution.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Extra question:

You are creating a Catalog Task (sc_task), though not giving it a parent record. What is the thought behind this? This way you will have a floating task.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

I am trying to create a new catalog task when these condition satisfies.

 

Regards,

Nivedita

niveditakumari
Mega Sage

Hi,

Any help would be appreciated.

 

Regards,

Nivedita