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

Deepak Ingale1
Mega Sage

Hi Nivedita,

 

You can write ASYNC business rule on sys_user table with condition as current.active.changes() && !current.active

 

in script you can put below code

 

 var gr = new GlideRecord("task");

gr.initialize();

gr.short_description = "User account " + current.getValue("first_name") + "  " + current.getValue("last_name") + " is marked inactive"

gr.insert();

 

Note: This is a sample code which will give you an idea on how to fulfill your requirement. Please mark reply as correct /helpful if it has answered your question

Mark Roethof
Tera Patron
Tera Patron

Hi there,

What exactly do you mean by a task? An incident? A Catalog Task? Etc.. Below steps could help you find a way.

find_real_file.png

find_real_file.png

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

niveditakumari
Mega Sage

Hi,

Thanks for all your response.

I have to put one more condition like user profile is inactive and user is having "xxx" application assigned on their profile then it should create one task.

Can you please help with these two condition.

Below is screenshot : 

 

Regards,

Nivedita

niveditakumari
Mega Sage

Hi,

Is there any suggestions on this?

 

Regards,

Nivedita