- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 11:42 PM
Dear all,
I could not find the steps to trigger an event using ScheduleJob.
Could anyone point me out steps by step
regards
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 07:27 AM
As per the documentation, the gr is a glide record object. To be honest i'm not 100% sure on its purpose or function in this context.
It's not something you can use and reference in your mail script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 02:31 AM
Ah ok, so you want to get a list of all records where the send mail field is true and send a notification to someone with all those records listed in the body? If that's what you need you'll need to push the records to an array and then pass that back in the eventQueue. You can then use a mail script to present that in your notification. eg:
//scheduled job:
var arr = [];
var gr = new GlideRecord('table_name');
gr.addQuery('field', value);
gr.query();
while(gr.next()){
arr.push(gr.getValue('name');
}
gs.eventQueue('event.name', gr, [recipients if you have them], arr);
//mail script:
var records = event.parm2;
template.print(records);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 02:55 AM
Thnaks for your reply.
Yes this is what I need to do by sending colelcted records to an email body using an email script.
In my scenario, I need to display records fields (Name, State, CostCenter ) with corresponding value.
Now I am confuse with your script because all is in same place.
STEP1
So in my Scheduled Job updated script I have the script as define above :
//Build record object on asset table
var gr = new GlideRecord('alm_asset');
//Append the querry to generate the view record based on condition
gr.addEncodedQuery('u_send_record_to_mail=true');
gr.query();
//If tehre is at least one records, we fire the event
if(gr.getRowCount() > 0){
gs.eventQueue("Asset.retired.ccchange", gr);
while (gr.next()) {
//we reset the flag in order to avoid unneeded resend
gr.u_send_record_to_mail = false;
gr.update();
}
}
From my script above, my event is fired only if there is at least 1 records which exist
Q1 : At this point, the gs.eventQueue("Assets.retired.ccchange", gr), gr contains all return records correct ?
STEP2
I have then a Notification of type email which will be trig when the event will be fired.
Then I have a Notification Email Script define as below :
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
template.print("Records which has beend retired or have cost Center change. \n\n");
var gr = new GlideRecord ("alm_asset");
var asset = [];
gr.addQuery('u_send_record_to_mail', true);
gr.query();
while (gr.next()){
// ????? WHAT TO DO HERE ???????
}
template.print("<table border=1 boardercolor=black>");
template.print("<tr><th align='left'>name</th><th align='left'>State</th></tr>");
// ????? WHAT TO DO HERE TO WRITE EACH RECORD IN CORRECT CELL ???????
template.print("</table>");
})(current, template, email, email_action, event);
Q2 : How the RunMail script is linked to my event fire in schedule job to collect records ?
How can I update my script in order to get all collected records and add then inside my row in each field
(place holder is mark with ???? in my script above)
Thnaks for clarification
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 03:14 AM
OK, does your scheduled job trigger the event correctly? Not sure if the while loop will still run after the if statement.
If you're doing all the logic in the mail script you can populate the table something like below:
template.print("Records which has beend retired or have cost Center change. \n\n");
template.print("<table border=1 bordercolor=black>");
template.print("<tr><th align='left'>name</th><th align='left'>State</th></tr>");
var gr = new GlideRecord ("alm_asset");
gr.addQuery('u_send_record_to_mail', true);
gr.query();
while (gr.next()){
template.print('<tr><td>'+gr.name+'</td><td>'+gr.state+'</td><td>'+gr.cost_centre+'</td></tr>');
}
template.print("</table>");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 06:43 AM
Yes my Even is trigger correct as long as I set its second parameter to nul...instead of my glidRecord object gr, for some reason I do not know why my "gr" object is null if I passe it to my event ?
gs.eventQueue("Asset.retired.ccchange", gr);
Any idea ?
Q1 :How can I then pass to my Event the list of collected records in order to fetch them in my email directly instead of using mail script
Q2: how can I access my collected record param directly from my email notification body ?
I still have just that part to do and it is hard to understand when it is first time in this envionment
Thnaks for help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 07:06 AM
You don't need to send the collected records through in the event, you're retrieving them in the mail script.
If you want to collate the records in the scheduled job you could add objects to an array and pass that through as a parameter in the eventQueue (check out the documentation at the link Kalai sent below). You can reference that in the mail script as i have previously stated with event.parm1 or event.parm2.