Auto populate a text field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:03 AM
Hello developers, Can anyone share the logic, i need to auto populate a text field once if any user registers/submit an order(catalog form) for the first time. If another user registers then the auto populated number should be incremented by 1. Any help is appreciated . Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:12 AM
Hi,
Is there any particular format or prefix (INC00.., PRB00...) or its merely numbers (1,2,3,etc.) without prefix. Also, since it is for catalog, it is for particular item or for all items?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 05:18 AM - edited 01-25-2024 01:38 AM
Hi @Jaspal Singh , .Thanks for your response! yes like PR001,PR002 etc., it is for particluar catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:16 AM
Sure, you can achieve this by creating a business rule in ServiceNow. Here's a step-by-step guide:
1. Navigate to System Definition > Business Rules in ServiceNow.
2. Click on New to create a new business rule.
3. Give your business rule a name, for example, "Auto Increment Order Number".
4. Select the table you want this business rule to apply to. In your case, it would be the table that stores the catalog form submissions.
5. Set the "When to run" settings as follows:
- When: before
- Insert: true
6. In the "Advanced" tab, write a script to auto increment the order number. Here's a sample script:
javascript
(function executeRule(current, previous /*null when async*/) {
// Query the database to get the last order number
var gr = new GlideRecord(current.getTableName());
gr.orderByDesc('order_number');
gr.setLimit(1);
gr.query();
if (gr.next()) {
// If there's a previous order, increment the order number by 1
current.order_number = parseInt(gr.order_number, 10) + 1;
} else {
// If there's no previous order, set the order number to 1
current.order_number = 1;
}
})(current, previous);
7. Click on Submit to save the business rule.
Please note that you need to replace 'order_number' with the actual field name in your table that you want to auto increment. Also, make sure that the field type of your order number field is integer.
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Please visit : https://nowkb.com/home
Our Website :https://nowkb.com/home
Link - https://nowgpt.ai/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 03:45 AM
Hi @sumanta pal : Thanks for your response , i just needed an auto populated value of field which increments when another user registers.