- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 12:15 PM
Hello all. I have a background script created to update values on pretty much all of our templates in the system. However, we would like to add a field to all of the templates and populate the value of the field without having to go into each template manually. In the script below I'm trying to update the 'u_template' field with the value from the 'name' field (long story so don't ask haha) but since the u_template field isn't in any of the templates, it's not actually updating the record. Is there a way I can add the u_template field to the templates without doing it individually? TIA
// Create a new GlideRecord instance for the sys_template table
var templateGr = new GlideRecord('sys_template');
var count = 0;
// Add a condition to filter active templates where the global checkbox is false
templateGr.addQuery();
templateGr.addQuery('active', true);
templateGr.addQuery('global', true);
// Execute the query
templateGr.query();
// Loop through the results
while (templateGr._next()) {
count++;
//templateGr.global = true; // Was previously used to set the global vlue to true
templateGr.u_template = templateGr.name; // Set the template name field to the name of the template
templateGr.update(); // Update the record
gs.info('Template name: ' + templateGr.name);
gs.info('Template name: ' + templateGr.u_template);
}
gs.info(count);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 09:14 AM
According to support, this is not possible:
"Thank you for your update. I have checked this further internally and also with a team lead and unfortunately, there is no ServiceNow API that is able to achieve the functionality you are looking for.
We apologize for the inconvenience this may cause. As mentioned previously if you think this can be a useful functionality, then we recommend creating an enhancement request
We have moved this case to the solution proposed state. Please let us know if you have any additional questions. Otherwise, you may accept the solution and bring the case to a close. "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 01:14 PM
Your script updated 174 of the 175 records I have in that table that meet the query conditions. (After creating the custom field.)
I do see:
Background message, type:error, message: You cannot create HR Template for Auto-Close HR task type
In the output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2024 08:19 AM - edited ‎01-30-2024 08:20 AM
Did the script actually update the records and add the field to them though? Because what I noticed is that the script says it updated the records, but if you comment out the lines that set the value and update the record (essentially just logging the info) and then run the script again, you can see that the update isn't actually happening because the u_template field doesn't return a value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2024 04:25 PM
yes, It worked for me as I indicated. And running the script again as you suggest, I see the values for the 'u_template' field set by running your script. Here's some output:
*** Script: Template name: Hiring Manager Checklist
*** Script: u_template name: Hiring Manager Checklist
*** Script: Template name: Background Check - Request Information
*** Script: u_template name: Background Check - Request Information
*** Script: Template name: Employee Travel Visa Request
*** Script: u_template name: Employee Travel Visa Request
*** Script: Template name: Schedule Manager 1:1
*** Script: u_template name: Schedule Manager 1:1
*** Script: Template name: Send welcome back note
*** Script: u_template name: Send welcome back note
*** Script: Template name: Template For Employee Verification
*** Script: u_template name: Template For Employee Verification
*** Script: Template name: Enroll child in Benefits
*** Script: u_template name: Enroll child in Benefits
*** Script: Template name: New Hire Documentation
*** Script: u_template name: New Hire Documentation
*** Script: Template name: HR Accounts Inquiry
*** Script: u_template name: HR Accounts Inquiry
*** Script: Template name: Schedule Mentor 1:1
*** Script: u_template name: Schedule Mentor 1:1
*** Script: Template name: Direct Deposit Inquiry
*** Script: u_template name: Direct Deposit Inquiry
*** Script: Template name: Begin Engineering Training Courses
*** Script: u_template name: Begin Engineering Training Courses
*** Script: Template name: Mentor Check-in
*** Script: u_template name: Mentor Check-in
*** Script: Template name: Approval Decision for leave of absence
*** Script: u_template name: Approval Decision for leave of absence
*** Script: Template name: Microsoft Monthly Patching Cycle
*** Script: u_template name: Microsoft Monthly Patching Cycle
*** Script: Template name: Request Background Check by Sterling
*** Script: u_template name: Request Background Check by Sterling
*** Script: Template name: Add network switch to datacenter cabinet
*** Script: u_template name: Add network switch to datacenter cabinet
*** Script: Template name: PIP assessment task template
*** Script: u_template name: PIP assessment task template
*** Script: Template name: Assign New Hire Project
*** Script: u_template name: Assign New Hire Project
*** Script: Template name: General Inquiry
*** Script: u_template name: General Inquiry
*** Script: Template name: Confirm child's birth, adoption, or placement date
*** Script: u_template name: Confirm child's birth, adoption, or placement date
*** Script: Template name: New Hire Project
*** Script: u_template name: New Hire Project
*** Script: Template name: Sign IP
*** Script: u_template name: Sign IP
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2024 08:25 AM
Hmmm.... I wonder why that's not working for me then. I have a case open with support, so hopefully that will generate a result.