How get next number while insert()?

adarsh-homepage
Kilo Contributor

Var inc = new GlideRecord('u_state_filing');

Var inc1= new GlideRecord('sys_choice');

Inc1.addEncodedQuery('u_state_filing^element=u_provinces');

Inc1.query();

while(Inc1.next()){

inc.u_parent_number= current_sys.id;

Var SysID = inc.insert();

Var MySysID= current.update();}

Basically I have a choice field and want to create same number of records, as choice numbers.also want to set the choice for each record as per selection.

Tried with for Loop but did not work.

7 REPLIES 7

adarsh-homepage
Kilo Contributor

Capture.PNG


Thanks Chuck for the response, as per the above image highlighted Value field need to be filled in u_provinces for new record. But It does not set the value for each record that is created.


For eg;   for 1st record set u_provinces= AB


                                    2nd record set u_provinces=BA


                                                and so on


                                      till last record set u_provinces= GL


I tried this another way, through List type field;


As this comma separated, I created a choice (ALL) with it;s value(AB,BA,CD). It did create 3 records but u_provinces got new choices as AB\...next   BA\..   next CD


If I select all the choices, and then select UI action it does create records as required. However, If I again select it does create same set of records.


Using the choice list field the way you had should work. Just add your field assignment where I had the comment.



var choice = new GlideRecord('sys_choice');


choice.addEncodedQuery('u_state_filing^element=u_provinces^language=en^inactive=false');


choice.query();


while(choice.next()){


        var inc = new GlideRecord('u_state_filing');


        inc.newRecord();


        inc.u_parent_number = current.sys_id;


        // add other inc field values here


        inc.u_provinces = choice.getValue('value');


        inc.insert();


}


adarsh-homepage
Kilo Contributor

Thanks Chuck for this. I am trying to copy the record while I have same parent number