- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 04:03 AM
I'm trying to developer a background script that will update the value of the 'Next AMA Due Date' field, but in order to do that, I need to retrieve the value of the date from the 'Last AMA Scoping Date' field and add a year to it. I've tried to run the following script in the background, however, nothing is happening:
var app = new GlideRecord('cmdb_ci_business_app');
var correctDate = new GlideDateTime();
app.addEncodedQuery('u_next_ama_due_dateNSAMEASu_last_scoping_ama_completed_date@day^u_in_scope_for_controls=not_in_scope^number=AL05053');
app.query();
while(app.next()) {
correctDate = new GlideDateTime(app.u_last_scoping_ama_completed_date);
correctDate.addYearsUTC(1);
app.setValue('u_next_ama_due_date', correctDate);
app.update();
}
Is anyone able to see that issue and explain where I'm going wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 05:05 AM
I managed to get it to work by using the following script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 04:23 AM
Add some gs.print lines to log what is happening - are any records returned by the GR? What is the value of correctDate before and after addYears?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 04:32 AM
// Initialize GlideRecord for cmdb_ci_business_app table
var app = new GlideRecord('cmdb_ci_business_app');
// Add encoded query to filter records
app.addEncodedQuery('u_in_scope_for_controls=not_in_scope^number=AL05053'); // Adjust this query as per your requirements
app.query(); // Execute the query
// Loop through each record matching the query
while (app.next()) {
// Retrieve the value of 'u_last_scoping_ama_completed_date' and add a year
var lastScopingDate = new GlideDateTime(app.u_last_scoping_ama_completed_date);
lastScopingDate.addYearsUTC(1);
// Set the value of 'u_next_ama_due_date' to the calculated date
app.u_next_ama_due_date = lastScopingDate;
// Update the record
app.update();
}
----------------------------------------
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 05:05 AM
I managed to get it to work by using the following script: