Auto request creation based on frequency

Rashmi Kumari S
Tera Contributor

Hi All,

 

I have a requirement to create a scheduled job to auto create a request based on below frequency. Frequency comes from decision table..

 

Monthly - 10th day of every month

Quarterly - 1st month of each quarter & 25th day... Eg. - Jan 25th, Apr 25th , July 25th, oct 25th

Yearly - 1 = Jan, 2 = Feb, 3 = March etc... 

 

Using the below code to create the request , looking for ideas to execute the job as per above schedule:

 

var bb = 9af90a951bffd210b2ac315f034bcb0a;
var gr = new GlideRecord('sys_decision_question');
gr.addQuery('decision_table',bb);
gr.addEncodedQuery('conditionLIKEu_review_code');
gr.query();
var arr = [];
while(gr.next())
{
arr.push(gr.condition.substring(14,20));
}

var dtpi2 = new sn_dt.DecisionTableAPI();
for(var i=0;i<arr.length;i++){
var decisionInputs2 =
{
u_review_code: arr[i]
};
var response2 = dtpi2.getDecision(bb, decisionInputs2);
var obj=
{
"review_code": arr[i],
};

arr2.push(obj);
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('3dece6cf1bded610b2ac315f034bcb11');
cart.setVariable(item,"review_code",arr[i]);
cart.setVariable(item,"requested_for",response2.result_elements.u_requested_for);
cart.setVariable(item,"application_service",response2.result_elements.u_application);
var rc = cart.placeOrder();
}

3 REPLIES 3

Priyanka_786
Tera Guru
Tera Guru

@Rashmi Kumari S 

You can user either scheduled job script or Flow designer. However in both the ways you need to do scripting as for yearly and quarterly options are not available as per OOB configuration.

 

You can use scheduled job script execution. There will be 3 separate scheduled jobs as per the schedule conditions.

For the first schedule condition, it is straightforward. Select run Monthly and day as 10 and write your script logic in run script section.

For Quarterly and yearly logic unfortunately currently don't have triggers as OOB configuration. You need to write script. For this, select run as daily and check Conditional checkbox and write script in condition script box.

Refer these threads for reference

https://www.servicenow.com/community/itsm-forum/send-a-notification-quarterly-to-group-managers-to-m...

https://www.servicenow.com/community/developer-forum/need-help-on-trigger-notification-quarterly/m-p...

Hope it helps.

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Regards,

Priyanka Salunke

 

JohnnySnow
Kilo Sage

@Rashmi Kumari S Flow designer is a better approach and easily maintainable.

Can you share the screenshot of your decision table.

 

Thanks
Johnny

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

@JohnnySnow Decision table looks like this..

RashmiKumariS_0-1742800502534.png