- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 02:46 AM
Hello All
i am trying to create a business rule, onbefore, with condition
user type is student.
I thought under actions i could have selected something like ''create a new record'' but i can't, and from reading online it seems i can only do it via scripting.
Does anyone know what am i supposed to write for this to happen?
The idea is, if user type is student, create a new record in the csm_consumer table and link the two
thanks to anyone who can help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 03:14 AM
Hello @Marta G ,
Check this link where a new record it's created from business rule: https://www.servicenow.com/community/developer-forum/create-a-business-rule-to-insert-a-record-when-...
☆ Community Rising Star 22, 23 & 24 ☆

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 03:17 AM - edited 05-03-2024 03:20 AM
Hi @Marta G ,
Please create before BR and add below script this will help you
var gr = new GlideRecord('tableName'); // Give your table name here
gr.initialize();
gr.short_description = current.short_description
gr.insert();
For Example you want to create new incident when user is created so you have to create BR on user table and glideRecord on incident table
var gr = new GlideRecord('incindet'); // Give your table name here
gr.initialize();
gr.short_description = "New User inserted name - " + current.first_name + current.last_name
gr.insert();
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 09:18 AM
Hi @Marta G,
Whilst others have guided you on the creation of a record via a Business Rule which is correct in concept, a best practice tip would be to avoid using the variable 'gr'. It is important to understand a "gr" defined in one business rule can clobber another "gr" defined in some other script, which happens to be running as part of the same update or transaction.
You should name your variables uniquely as well as wrap your scripts in a function to avoid your script clobbering another as shown below:
function createIncident() {
var createIncidentGr = new GlideRecord('incident');
createIncidentGr.initialize();
createIncidentGr.short_description = 'Example record Creation'; // or grab an existing value such as current.field_name
createIncidentGr.insert();
}
createIncident(); // runs the above function
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
SN Developer and Best Practice article on this subject:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 03:14 AM
Hello @Marta G ,
Check this link where a new record it's created from business rule: https://www.servicenow.com/community/developer-forum/create-a-business-rule-to-insert-a-record-when-...
☆ Community Rising Star 22, 23 & 24 ☆

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 03:17 AM - edited 05-03-2024 03:20 AM
Hi @Marta G ,
Please create before BR and add below script this will help you
var gr = new GlideRecord('tableName'); // Give your table name here
gr.initialize();
gr.short_description = current.short_description
gr.insert();
For Example you want to create new incident when user is created so you have to create BR on user table and glideRecord on incident table
var gr = new GlideRecord('incindet'); // Give your table name here
gr.initialize();
gr.short_description = "New User inserted name - " + current.first_name + current.last_name
gr.insert();
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 09:18 AM
Hi @Marta G,
Whilst others have guided you on the creation of a record via a Business Rule which is correct in concept, a best practice tip would be to avoid using the variable 'gr'. It is important to understand a "gr" defined in one business rule can clobber another "gr" defined in some other script, which happens to be running as part of the same update or transaction.
You should name your variables uniquely as well as wrap your scripts in a function to avoid your script clobbering another as shown below:
function createIncident() {
var createIncidentGr = new GlideRecord('incident');
createIncidentGr.initialize();
createIncidentGr.short_description = 'Example record Creation'; // or grab an existing value such as current.field_name
createIncidentGr.insert();
}
createIncident(); // runs the above function
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
SN Developer and Best Practice article on this subject: