In Record Producer, I want to create multiple records in a single submit( Parent --> Child --> Child
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 01:08 AM - edited 01-11-2024 02:00 AM
Hello All,
In Record Producer, I want to create multiple records in a single submit.
I am assuming this is the same as when sending a catalog item, where a Request and RequestItem record and catalog task is created at the same time.
Also, when three records (1), (2) and (3) are created, we want to make (2) to (1) and (3) to (2)
What I want to know is the following two things.
1. How to create multiple records in a single submit.
2. Also, when three records (1), (2) and (3) are created, we want to make (2) to (1) and (3) to (2)
As mentioned above, the same thing is done in Request and RequestItem and catalog task
If anyone knows where this is done, we would like to know.
want to achieve this with Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 01:10 AM - edited 01-11-2024 01:11 AM
To create multiple records in a single submit using a Record Producer, you can use the script section of the Record Producer. Here's a simple example:
1. Navigate to Service Catalog > Catalog Definitions > Record Producers.
2. Open the Record Producer where you want to add the functionality.
3. In the script section, you can add a script to create multiple records. Here's a simple example:
javascript
(function execute() {
// Create first record
var gr1 = new GlideRecord('table_name');
gr1.field1 = producer.field1;
gr1.field2 = producer.field2;
gr1.insert();
// Create second record
var gr2 = new GlideRecord('table_name');
gr2.field1 = producer.field1;
gr2.field2 = producer.field2;
gr2.insert();
// Create third record
var gr3 = new GlideRecord('table_name');
gr3.field1 = producer.field1;
gr3.field2 = producer.field2;
gr3.insert();
})();
In this script, replace 'table_name' with the actual table name where you want to create the records, and 'field1' and 'field2' with the actual field names.
To link the records (2) and (3) to record (1), you can use a reference field in the table. Here's how you can do it:
javascript
(function execute() {
// Create first record
var gr1 = new GlideRecord('table_name');
gr1.field1 = producer.field1;
gr1.field2 = producer.field2;
gr1.insert();
// Create second record and link it to the first record
var gr2 = new GlideRecord('table_name');
gr2.field1 = producer.field1;
gr2.field2 = producer.field2;
gr2.reference_field = gr1.sys_id; // Link to the first record
gr2.insert();
// Create third record and link it to the first record
var gr3 = new GlideRecord('table_name');
gr3.field1 = producer.field1;
gr3.field2 = producer.field2;
gr3.reference_field = gr1.sys_id; // Link to the first record
gr3.insert();
})();
In this script, replace 'reference_field' with the actual reference field name in your table. This field should be a reference to the same table, and it will be used to link the records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 01:44 AM
Hi Rajdeep,
I want to link record (2) to (1) and (3) to (2) through record producer how to achieve this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 02:48 AM
To link records through a record producer in ServiceNow, you can follow these steps:
1. Create a Record Producer: Navigate to Service Catalog > Catalog Definitions > Record Producers. Click on New to create a new record producer.
2. Define the Table: In the Table field, select the table where you want to create the record.
3. Create Variables: Create variables that will capture the information you need from the user. These variables will be used to populate the fields in the new record.
4. Write a Script: In the Script field, write a script that will create the new record and link it to the existing records. Here is a sample script:
javascript
(function execute() {
// Create a new GlideRecord for the table where you want to create the record
var gr = new GlideRecord('table_name');
// Set the fields in the new record using the variables from the record producer
gr.field1 = producer.variable1;
gr.field2 = producer.variable2;
// ...
// Insert the new record
gr.insert();
// Link the new record to the existing records
var gr1 = new GlideRecord('table_name');
if (gr1.get('sys_id', 'id_of_record_1')) {
gr1.field_linking_to_new_record = gr.sys_id;
gr1.update();
}
var gr2 = new GlideRecord('table_name');
if (gr2.get('sys_id', 'id_of_record_2')) {
gr2.field_linking_to_new_record = gr.sys_id;
gr2.update();
}
})();
5. Test the Record Producer: Navigate to the Service Catalog and find your record producer. Fill in the variables and submit the form. Check the table where you are creating the new record and verify that it has been created and linked to the existing records correctly.
Please replace 'table_name', 'field1', 'field2', 'variable1', 'variable2', 'field_linking_to_new_record', 'id_of_record_1', and 'id_of_record_2' with your actual table names, field names, variable names, and record IDs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 03:23 AM
I would like to create three records together from record Producer