Create tasks from form onsubmit

allen_pitts
Giga Expert

Hello implement community,

 

A new server request has been implemented in the Service Catalog.

To get new server requests out of the emails and hallway conversations

the Service Catalog item was kept simple so it could be implemented

immediately. Right now the Service Catalog item creates a Request,

a Request Item, a Notification and a Request Task.

 

The task and notification goes to the engineer that coordinates new servers   who

then uses an application developed for this purpose called Operational

Projects or Ops Projects. The engineer creates nine tasks associated

with the Ops Project.

 

The tasks would be created from the OnSubmit event at the Ops Project

form when the field labeled 'Project Type' equals "New Server'.

Business rule condition
u_ops_project.u_project_type.indexOf("New System") == 0

Several of the fields from the Ops Project form will auto populate

in the Ops Projects Tasks.

 

If the Sys Admin training is remembered correctly, the way to get the
tasks created by the system would be a business rule as opposed to a client script

because the script must run at the server to create the tasks.

Any tips, tricks or pitfalls? Syntax for creating tasks in business rule?

Thank

 

Allen Pitts
LHP Hospital Group

1 ACCEPTED SOLUTION

domaners
Kilo Guru

Personally I would recommend using a Workflow to handle this type of activity, as you can template your individual tasks without the need for using code. However, if you do need to script these events, use a Glide Record to create the tasks. Article:



GlideRecord - ServiceNow Wiki



Cheers, Adam


View solution in original post

10 REPLIES 10

domaners
Kilo Guru

Personally I would recommend using a Workflow to handle this type of activity, as you can template your individual tasks without the need for using code. However, if you do need to script these events, use a Glide Record to create the tasks. Article:



GlideRecord - ServiceNow Wiki



Cheers, Adam


Hello Adam and Derek,



Thanks for your excellent replies.



Ok, I see where the workflow is probably the best practice.


(I have about six years with web development and JavaScript


but I am pretty new to ServiceNow so bear with me please.)


At Workflow>Workflow editor>New Workflow


Select the table (u_ops_project) with the condition


(Project Type is New Server. Submit.


Then from menu on right. Create Task


This is where I sort get stuck because the new server coordinator


sort of expects to see nine tasks created as shown in the GIF


below marked 'Ops Project' (The tasks are at the bottom)


One of the tasks should be like the GIf marked 'Figure 2.


Ops Task Create Runbook'. But the Form in the Workflow, New Activity


Create Task does not allow the creation of a task like


Ops Task Create Runbook. In other words how to get the task
created by New Activity Create task form have the fields
in the GIF herewith below?



Also is the 'Task dictionary created in the workflow
area or somewhere else?



Don't need to be tutored but maybe pointed in the right direction.



Thanks.




Ops _Project_Screen_shot_140520_b.gifOps _Task_Create_Runbook_Screen_shot_140516.gifOps Task pictured


Allen,



Sorry, let me try and clarify a little bit. I was suggesting one of two options:



1) The workflow


2) Using just business rules



To explain #2 a little bit more.



For a client we built a "task dictionary" which was just another table and module where the client would create several tasks that would be created every time. This allowed the admins to update the necessary tasks there rather than in code. To apply this idea to your "New Server" situation: the admin would create nine tasks in the task dictionary with a description, type, etc (whatever you want in there).



Whenever a "New Server" is created, the business rule would look at that task dictionary table and create 9 new tasks that were then linked to the "New Server" record just created.



I hope that clarifies what I was saying a little bit more. Let me know if not.



Again, just an idea. If you can get the workflow running, that might be a better option.


Hello Derek,



It was understood that the workflow or business rule was an either or
deal.
So lets go with business rule because that seems to be simpler.
A business rule was written that would write a message to the log.



// write message to log 140520 acp


var msg = "Log message written by business rule 140520" + gs.now();


gs.log(msg);



It was thought that when a new Ops Project was created an Insert would be
done the business rule would be fired and the message would be written to the
log. But there is no message in the log.



Any ideas?



Allen
Business_rule_140520.gif