- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 07:47 PM
Hi All,
I have a requirement,
In Record Producer I have "List Collector" Field (name: related_claims ) and I need to insert multiple records based on number of selections in List Collector field for this I have written a script in record producer level kindly check below script
For example: If I choose two values in "related_claims" Field it should create two records in the table but It creates 3 records one record is creating from record producer and remaining two are creating from for loop and target field is not updating (i.e: u_related_claim after splitting list collector field I need to update this field but out of 2 inserted records only one is updating other one not updating ) to restrict 3rd record while submitting I have written like current.setAbortAction(true) after written this line it is working as expected the only concern is it should not skip auto generated number (i.e INC000XXX) ) but here I observed that it is skipping auto generated number Ex: last inserted record number is INC0000236 it created two records like INC0000238, INC0000239. so here it skipped INC0000237 to overcome this I tried few approaches but didn't work can anyone kindly assist me in this.
Thanks in advance
Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 03:44 AM
Try the below please send the screenshot :-
if ((producer.category == '4000') && (producer.subcategory == '4054')) {
var claims = producer.related_claims.toString();
var list = claims.split(',');
gs.info('Claims: ' + claims);
current.setAbortAction(true);
// Insert records based on List Collector selections
for (var i = 0; i < list.length; i++) {
var claim = list[i].trim(); // Trim any extra spaces
gs.info('Processing claim: ' + claim);
if (claim) { // Ensure claim is not empty
try {
var gr = new GlideRecord('sn_customerservice_case');
gr.category = producer.category;
gr.subcategory = producer.subcategory;
gr.short_description = producer.short_description;
gr.partner = producer.account;
gr.assigned_to = producer.assigned_to;
gr.parent = producer.parent;
gr.contact = producer.contact;
gr.u_contact_email = producer.u_contact_email;
gr.u_related_order = producer.u_related_order;
gr.u_related_claim = claim; // Update with specific claim
gr.u_hp_contact_region = producer.u_hp_contact_region;
var newSysId = gr.insert();
gs.info('Inserted record with Sys ID: ' + newSysId);
} catch (e) {
gs.error('Error inserting record for claim: ' + claim + ', Error: ' + e.message);
}
} else {
gs.warn('Skipping empty claim value at index: ' + i);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 02:47 AM
Hello Ravi,
I have modified the script and tested still it is skipping two auto generated numbers, I did check logs and it did not went to catch block
Logs:
Inserted record with Sys ID: 161b555f470c56d0a83c7351e36d4361
Inserted record with Sys ID: ee1b555f470c56d0a83c7351e36d4366
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 03:44 AM
Try the below please send the screenshot :-
if ((producer.category == '4000') && (producer.subcategory == '4054')) {
var claims = producer.related_claims.toString();
var list = claims.split(',');
gs.info('Claims: ' + claims);
current.setAbortAction(true);
// Insert records based on List Collector selections
for (var i = 0; i < list.length; i++) {
var claim = list[i].trim(); // Trim any extra spaces
gs.info('Processing claim: ' + claim);
if (claim) { // Ensure claim is not empty
try {
var gr = new GlideRecord('sn_customerservice_case');
gr.category = producer.category;
gr.subcategory = producer.subcategory;
gr.short_description = producer.short_description;
gr.partner = producer.account;
gr.assigned_to = producer.assigned_to;
gr.parent = producer.parent;
gr.contact = producer.contact;
gr.u_contact_email = producer.u_contact_email;
gr.u_related_order = producer.u_related_order;
gr.u_related_claim = claim; // Update with specific claim
gr.u_hp_contact_region = producer.u_hp_contact_region;
var newSysId = gr.insert();
gs.info('Inserted record with Sys ID: ' + newSysId);
} catch (e) {
gs.error('Error inserting record for claim: ' + claim + ', Error: ' + e.message);
}
} else {
gs.warn('Skipping empty claim value at index: ' + i);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 05:08 AM
Hi Ravi
Updated above script and tested, now it is skipping 1 autogenerated number
Kindly check below logs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 07:43 AM
Atleast accept the solution.. its working for you... only one is skipping..We are trying hard to provide you the solution
try the below
if ((producer.category == '4000') && (producer.subcategory == '4054')) {
var claims = producer.related_claims.toString();
var list = claims.split(',');
gs.info('Claims: ' + claims);
// Insert records based on List Collector selections
for (var i = 0; i < list.length; i++) {
var claim = list[i].trim(); // Trim any extra spaces
gs.info('Processing claim: ' + claim);
if (claim) { // Ensure claim is not empty
try {
var gr = new GlideRecord('sn_customerservice_case');
gr.category = producer.category;
gr.subcategory = producer.subcategory;
gr.short_description = producer.short_description;
gr.partner = producer.account;
gr.assigned_to = producer.assigned_to;
gr.parent = producer.parent;
gr.contact = producer.contact;
gr.u_contact_email = producer.u_contact_email;
gr.u_related_order = producer.u_related_order;
gr.u_related_claim = claim; // Update with specific claim
gr.u_hp_contact_region = producer.u_hp_contact_region;
var newSysId = gr.insert();
gs.info('Inserted record with Sys ID: ' + newSysId);
} catch (e) {
gs.error('Error inserting record for claim: ' + claim + ', Error: ' + e.message);
}
} else {
gs.warn('Skipping empty claim value at index: ' + i);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 01:25 AM
Hi @Srinivas K1
Please try below script.
if ((producer.category == '4000') && (producer.subcategory == '4054')) {
var claims = producer.related_claims.toString();
var list = claims.split(',');
current.u_related_claim = list[0].toString();
for (var i = 1; i < list.length; i++) {
var gr = new GlideRecord('sn_customerservice_case');
gr.category = producer.category;
gr.subcategory = producer.subcategory;
gr.short_description = producer.short_description;
gr.partner = producer.account;
gr.assigned_to = producer.assigned_to;
gr.parent = producer.parent;
gr.contact = producer.contact;
gr.u_contact_email = producer.u_contact_email;
gr.u_related_order = producer.u_related_order;
gr.u_related_claim = list[i].toString();
gr.u_hp_contact_region = producer.u_hp_contact_region;
gr.insert();
}
}
If my answer helped you in any way, please then mark it as helpful or correct.