insert records with different short descrition using background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 11:40 PM
Hi @all
var increcord = new GlideRecord('incident');
for(i=1;i<=100;i++){
increcord.initialize();
increcord.short_description = 'test '+' '+ i;
increcord.state == 3;
increcord.insert();
}
here I am trying to insert 100 records into the instance using background script with different short description for each record can anyone help me how shall I do it using script ? short description can be different as using inc number and other sentences.
thanks!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 02:46 AM
Possibly.
Please explain further. I'm not sure if I understand your scenario.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2024 03:09 AM
Hi @tGhadage
After reviewing your script, I noticed a few issues:
- You should use the assignment operator = instead of == in incRecord.state = 3;, as you’re setting the state value rather than comparing it.
- Your script sets the state directly to "On Hold." Instead, consider setting the initial state to "New" or "WIP" as per the process. Also, when setting the state to "On Hold," make sure to specify the "On Hold Reason."
- To follow best practices, ensure that you account for all mandatory fields required by the table when inserting records.
Here's a revised script for your reference:
var incRecord = new GlideRecord('incident');
for (var i = 1; i <= 100; i++) {
incRecord.initialize();
incRecord.caller_id = gs.getUserID(); // Set caller to logged-in user
incRecord.short_description = 'test ' + i; // Unique short description
incRecord.state = 3; // On-Hold State
incRecord.hold_reason = 1; // On Hold Reason
incRecord.insert();
}
This will definitely help you resolve your issue. Let me know if you need any guidance on ServiceNow scripting best practices; you can DM me on LinkedIn.
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Best Regards,
Krushna Birla
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 04:26 AM
Hi @tGhadage
Did you tried this approach
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Best Regards,
Krushna Birla