- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 10:54 AM
I am wondering how I can start a workflow from a script? I've seen various examples on community, but nothing that's really making sense for what I'm attempting to do. In my script, I'm looking for records that are going to expire in 60 days. That piece of the script is working great and my count of 3 that's returned after running is accurate. However, I'm then trying to trigger a workflow for each of those records that are found so I can assign tasks to a particular group. When I tried the script below, the system ended up starting roughly 5,500 instances of the workflow. We only have about 400 records in the u_cmdb_ci_certificates table, so I'm confused as to why that happened considering those numbers don't line up and I only had 3 returned results from the GlideRecord.
For bonus points, I'll also need to pass the name and certificate_expiration fields to the workflow so that teams who received the tasks know which certificate to look at.
Here is what I have so far:
var gr = new GlideRecord('u_cmdb_ci_certificates');
var count = 0;
var strQuery = 'u_certificate_expirationRELATIVEGT@dayofweek@ahead@59';
strQuery = strQuery + '^u_certificate_expirationRELATIVELT@dayofweek@ahead@61'
strQuery = strQuery + '^u_retired=false'
gr.addEncodedQuery(strQuery);
gr.query();
while (gr.next()) {
count++;
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('Certificate Expiration'), gr, 'insert');
}
gs.log("This is how many records were found: " + count)
Solved! Go to Solution.
- Labels:
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 11:58 AM
While the back story of how this script started is way too long to get into, I wanted to say that I sort of gave up on the script after running into lots of issues.
However what I'm doing is basically the exact same query, but I'm doing it in Flow Designer. From there, for each of those records, I'm submitting a catalog request. The catalog request then has the workflow tied to it. So from the standpoint of what I was trying to do above, for every record that is about to expire, the workflow is triggered.
Hope this helps someone looking to do something similar!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 11:58 AM
While the back story of how this script started is way too long to get into, I wanted to say that I sort of gave up on the script after running into lots of issues.
However what I'm doing is basically the exact same query, but I'm doing it in Flow Designer. From there, for each of those records, I'm submitting a catalog request. The catalog request then has the workflow tied to it. So from the standpoint of what I was trying to do above, for every record that is about to expire, the workflow is triggered.
Hope this helps someone looking to do something similar!