The CreatorCon Call for Content is officially open! Get started here.

Condition Script

yoli1
Tera Contributor

Hi team, is there a possibility to add a custom field to the scheduled jobs form, allowing the user to choose how many months until the scheduled job is triggered again? For example, if they want it to run on a quarterly basis, they can simply select '3 months' instead of using a Condition Script

14 REPLIES 14

yoli1
Tera Contributor

Hi @Bert_c1 but this will only executes once am i right? if the user chooses 2 months the job will executes after 2 months and that's it? not every 2 months

i'am looking for : every x months 

hi @yoli1,

 

If you add that logic at the end of your script, each time it runs it will "re-schedule" the job for the number of months the custom field is set to.

 

The are other types of Scheduled jobs, such as report generation, that would need a different solution.

 

You have mentioned "months" and "quarterly" here. If predicable and you don't want to use "Days" for "Periodically", then use business calendar for quarterly/semi-annual/annual. Or use script logic for Months, since that is not available OOB.

JamesEcoStratus
Mega Guru

To add a custom field to the Scheduled Jobs form in ServiceNow that allows users to choose how many months until the scheduled job is triggered again, you'll need to create a new field and customize the Scheduled Jobs form. Here are the steps to achieve this:

 

Step 1: Create a New Field

 

Go to "System Definition" > "Tables & Columns."

 

In the "Tables & Columns" module, find and select the "sysauto_script" table (Scheduled Jobs).

 

Click on the "Columns" tab.

 

Click "New" to create a new column for storing the number of months.

 

Configure the new column:

 

Name: Enter a name for the column, e.g., recurrence_months.

Label: Enter a user-friendly label, e.g., "Recurrence in Months."

Type: Choose "Integer" as the data type.

Max Length: Set an appropriate maximum length (e.g., 4).

Reference: Leave this empty.

Default value: You can set a default value if needed.

Mandatory: Select "Mandatory" if you want this field to be required.

Active: Ensure that the column is active.

Show in List: Optionally, you can choose to display this field in lists.

Save the new column.

 

Step 2: Modify the Scheduled Jobs Form

 

Go to "System Definition" > "Scheduled Jobs."

Open the Scheduled Job for which you want to add the custom field or create a new Scheduled Job.

In the form view, click the "Personalize Form" button (pencil icon) on the top-right corner.

In the form designer, drag the newly created "Recurrence in Months" field from the "Available" list to the form layout where you want it to appear.

Configure the field's properties in the form designer, such as label alignment and formatting, as per your preferences.

Click "Save" to save your changes in the form designer.

Exit the form designer.

 

Step 3: Test and Deploy

 

Test your custom field by creating or editing a Scheduled Job. You should now see the "Recurrence in Months" field on the form, allowing you to select the desired number of months.

Once you're satisfied with the functionality and appearance, you can deploy this change to your production environment.

 

Now, users can specify how many months until the scheduled job should be triggered again without needing to use a condition script. The value entered in the "Recurrence in Months" field can be used in your scheduled job script logic to determine when the job should run again.

Rajesh_Bhise
Tera Guru

Hello @yoli1 ,

 

Instead using the scheduled job, why can't you try the events and script actions.

 

Use custom field date and trigger the event based on it using method gs.eventQueueScheduled() and then you can do whatever you want using the script actions. Trigger script action by event.

 

Hope this would solve your problem. Please let me know if you need more help on this.

 

Please dont forget to mark helpful and correct answer if this fits your issue.

 

Thank You,

Rajesh

 

Hi @Rajesh_Bhise can you please help me with this i'm not familiar with events and script actions. Thanks a lot!