How to create scheduled task

Brahmi Pandla
Tera Guru

Hi Everyone

i created the scheduled job with below script for creating task

 

var createTsk = new GlideRecord('sc_task');
createTsk.initialize();
createTsk.requested_for = '661b4be04f00b7406209ecee0210c73b';
createTsk.short_description = 'update the conference room data';
createTsk.description = 'get the conference room data from AD, upload csv import in the task, and reassign task to TCS_Tools team';
createTsk.u_category = 'software_bus_app';
createTsk.u_subcategory = 'Data';
createTsk.assignment_group = 'e74c2a2fdb8b8810245b18df4b9619b5';
createTsk.state = '1';
createTsk.insert();
 
 
requested_for updated with the value
 
Could you please help on this
9 REPLIES 9

You can set it 

under for each record

caller / requested by = ABC

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

For each  unable to add filed value

BrahmiPandla_0-1742468919139.png

 

Hi @Brahmi Pandla 

 

It seems there’s something wrong here. I see in the scheduled job you're using the sc_task table, and the same approach should be applied here as well. However, the key point is determining the basis on which you're creating the sc_task and which request you're associating it with.

Here’s what you can do:

  1. When looking up records, search in the sc_task table.
  2. For the "Assigned to" field, use RITM.Requested for, and then add that in the flow.
*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

JohnnySnow
Kilo Sage

@Brahmi Pandla There are bunch of issues in your code,

1. Requested for that you see on the sc_task form is a field referencing sc_req_item form. Sc_task doesnt have a requested for field

2. Requested for and assignment groups are reference field so adding the sys id directly wont work.

3. Do you have to create an sc_task or just task? sc_task would need a RITM as well.

4. What is it that you are trying to achieve here?

5. Flow designer approach is easier to maintain and understand.

 

 

If you planning to use sctask and flow designer below would the approach

Overall

JohnnySnow_0-1742515407194.png

 

Details of each step

JohnnySnow_2-1742515460077.png

JohnnySnow_1-1742515444925.png

JohnnySnow_3-1742515481638.png

make sure to select the right RITM as shown above.

 

 

Please mark it as helpful or correct if it helped you resolve the issue or worked for you.

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

Chaitanya ILCR
Kilo Patron

Hi @Brahmi Pandla ,

you can schedule record generation using scheduled jobs

1. create a template

replace the table with your table and update template details

ChaitanyaILCR_1-1742521331532.png

 

2. go to scheduled jobs and click on new and click on "Automatically generate something (a change, an incident, a ci, etc) from a template "

ChaitanyaILCR_2-1742521506268.png

3. populate the detail and select the template that you have created in generate this field

ChaitanyaILCR_3-1742521592131.png

 

You can follow this approach when you have to generate something with static values 

 

coming to you requirement 

1. are you sure you want to generate SC task alone without RITM and why, what is the business requirement

2. if you want to submit a catalog item weekly that also you can do using flow

use submit a catalog item request action and fill the necessary details

ChaitanyaILCR_4-1742521851267.png

follow this approach for complete RITM process instead just creating a sctask

 

2. Requested For field is not available on the SC task it's available on Requested Item so your script won't set requested for value

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya