Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to autocreate RITM once date is expired

Gopal14
Tera Contributor

Hi Team,

 

How to auto create RITM once date is expired.

 

Ex:

Date is expired, then automatically needs to create Requested Item.

 

How to create automatically Requested Item

5 REPLIES 5

Rajesh Chopade1
Mega Sage

hi @Gopal14 

To automatically create a Requested Item (RITM) when a certain date is expired, you can use a combination of a scheduled job and a script.

 

Create a New Scheduled Job:

Run: Select how often you want this job to run (e.g., Daily, Hourly).

Condition: You can set a condition if you only want to check for specific criteria, but typically you will just run the job on a schedule.

Script: write script to create RITM

(function() {
    // Define the table where you are checking for expiration dates
    var gr = new GlideRecord('your_table_name'); // Replace with your table name
    gr.addQuery('expiration_date', '<=', new GlideDateTime()); // Adjust the field name
    gr.addQuery('state', '!=', 'closed'); // Optionally check that the state is not closed
    gr.query();

    while (gr.next()) {
        // Create the Requested Item (RITM)
        var ritm = new GlideRecord('sc_req_item');
        ritm.initialize();
        ritm.short_description = 'Auto-generated RITM for ' + gr.getDisplayValue('field_name'); // Adjust as needed
        ritm.request = gr.sys_id; // Associate with a request if needed
        ritm.u_custom_field = gr.u_custom_field; // Map any other fields as necessary
        ritm.insert(); // Insert the RITM
        
        // Optionally, you can log or handle errors
    }
})();

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Gopal14 

You can do this via Flow designer easily. In Flow designer you can schedule and put the condition.

*************************************************************************************************************
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]

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

Hi @Dr Atul G- LNG 

 

Gopal14_0-1727422831009.png

On this variable I want logged in user name needs to populate.  How can I achieve this in flow designer

Expert @Rajesh Chopade1  already provide the script. 

*************************************************************************************************************
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]

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