Insert multiple records from record producer using List Collector Type field

srinivas48
Tera Contributor

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: 

if ((producer.category == '4000') && (producer.subcategory == '4054')) {
    var claims = producer.related_claims.toString();
    var list = claims.split(',');
    gs.info('claimsssss' + claims);
    // current.u_related_claim = producer.related_claims.toString();
    for (var i = 0; i < list.length; i++) {
        // if (i == 0) {
        // current.u_related_claim = list[i];
        //     gs.info('ifstmt' + list[i] + " , " + i);
        // } else {
        var gr = new GlideRecord('sn_customerservice_case');
        gs.info('elsestmt' + list[i]);
        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();
        //current.setAbortAction(true);
    }
}
0 REPLIES 0