Create multiple requests from multiple closed requests
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 10:46 AM
The objective is to create multiple requests from closed requests via schedule job/business rule. Here is the scenario.
We have requests created manually for certificates to renew as they come up for expiration. Tasks are created, completed and the RITM is closed out with a future expiration date. All fine and good manually. This future expiration date is used in reports to see what is upcoming for expiring dates so new tickets can be created manually.
What i want to do is create a scheduled job which in turn runs a business rule that will review all closed RITMs that are certificates with a future date of the current date + 30 days and in turn create a new RITM systematically versus manually.
In many cases, i can have 2 or more closed RITMs with the same future expiration date, different data on each RITM, so i would need an auto-created RITM for each closed RITM as the data on each closed RITM will be different.
Example.
I have 3 closed RITMs that have a future expiration date of 11/16/2022. I need to update my current scheduled job to run my current business rule, find the 3 closed certificate RITMs and create 3 new cert RITMs, one for each of the closed ones with the appropriate fields filled in for each. So new RITM1 would replicate the data from closed RITM1, new RITM2 would replicate the fields from RITM2 and new RITM3 would replicate the fields from closed RITM3.
hope this makes sense.
i currently, in DEV, have a scheduled job that runs a business rule that can create an RITM but in the business rule script I have the fields to be filled in hard coded but for my project i need to pull fields from the closed RITMs.
Any coding examples that can be provided to help out is greatly appreciated. We do not have the certificate management module so the above scenario is what I am working on. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 12:45 PM
Hi, firstly you should not need to run a business rule from a scheduled job, if you need to call external repeatable script from a scheduled job then you should be rolling the code into a script-include function so that you can all from BR or scheduled job.
Is there a reason why you cannot record expiry dates against 'cert' records (they could be any type of CI) and utilize the content of your certs to populate your task records. This would be a better solution than querying old tasks records for details that may\may not be recorded correctly in the task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 05:50 AM
Hi Tony.
I'll see what i can do about about putting my bus rule script in my scheduled job and only using one of them. Can you provide some sample code on how, in a scheduled job, i would look at closed RITMs and copy data from a closed ticket to a new ticket? want to make sure i have correct syntax and not spin my wheels guessing.
Regarding the 'CI', we don't put certs in our CMDB, if that is what you are referencing. Our teams use other means to track inventory and don't use the Service Now CMDB at this time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 06:53 AM
Tony, below is the code i currently am working on. i finally got a ticket REQ/RITM to create but all the data fields come out as undefined. I'm sure it is something in the syntax some where but i can't figure it out. been working on this for a couple of days now. any help fixing the syntax is greatly appreciated.
var answer = false;
gs.log("at top of script");
var endAt = new GlideDateTime();
endAt.addDays(30);
var startAt = new GlideDateTime(endAt);
startAt.add(-43200000);
endAt.add(43200000);
var gr = new GlideRecord('sc_req_item');
gr.addQuery('active', false);
gr.addQuery('item', 'Certificate Request.');
gr.addQuery('cat_item.revised_updated_expiration_date', '>=', startAt);
gr.addQuery('cat_item.revised_updated_expiration_date', ',=', endAt);
//gr.addQuery('what_is_the_current_expiration_date_of_the_certificate', '>=', startAt);
//gr.addQuery('what_is_the_current_expiration_date_of_the_certificate', '>=', endAt);
gr.query();
answer = true;
gs.log("at end of condition 1");
(function() {
gs.log("at start of while loop 2");
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = '6e1733b137329f00c26fdaa543990efd';
var ritm = cart.addItem(item);
gs.log("after var item of cart add.item 3");
cart.setVariable(ritm, 'requested_for', '574dbcb30fa24200f1472ca8b1050e1b');
cart.setVariable(ritm, 'requested_by', '574dbcb30fa24200f1472ca8b1050e1b');
gs.log("after both requested names 4");
cart.setVariable(ritm, 'is_this_a_new_certificate_or_certificate_renewal', current.variables.is_this_a_new_certificate_or_certificate_renewal);
cart.setVariable(ritm, 'what_is_the_certificate_name', current.variables.what_is_the_certificate_name);
cart.setVariable(ritm, 'what_is_the_current_expiration_date_of_the_certificate', current.variables.what_is_the_current_expiration_date_of_the_certificate);
cart.setVariable(ritm, 'what_is_the certificate_environment', current.variables.what_is_the_certificate_environment);
cart.setVariable(ritm, 'will_this_certificate_be_externally_facing', current.variables.will_this_certificate_be_externally_facing);
cart.setVariable(ritm, 'does_service_assurance_team_need_to_be_involved', current.variables.does_service_assurance_need_to_be_involved);
cart.setVariable(ritm, 'service_partner', current.variables.service_partner);
cart.setVariable(ritm, 'description_of_certificate_request', current.variables.description_of_certificate_request);
cart.setVariable(ritm, 'impacted_services', current.variables.impacted_services);
gs.log("at the end of while loop before placeorder 5");
var placeOrder = cart.placeOrder();
})();