How get next number while insert()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2017 02:32 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2017 02:46 PM
Typo:
inc. u_parent_number=current.sys_id;
This is UI action script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2017 03:24 PM
It sounds like you want a while or for loop to create records. If someone selects "3" you get 3 records. Doing this from a UI Action is quite easy. Is the choice list on the u_state_filing table and you want to create 3 (for example) more u_state_filing records?
Here's an example based on my assumptions. Please let me know if any are incorrect.
var count = parseInt(current.getValue('u_provinces');
for (var i = 0; i < count; i++) {
var inc = new GlideRecord('u_state_filing');
inc.newRecord();
inc.u_parent_number = current.sys_id;
inc.insert();
}
That's about it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 07:55 AM
Thank Chuck for the script. However, I am trying to fetch all choices of u_pronvices without need to select. Then try to create records and setting those choices while insertion. Thatswhy, I calling sys_choice table to get this list of choices and create records accordingly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 05:48 AM
Thanks for the clarification. You're very close. I'd add a few more conditions to that encoded query however. Something like this. Again, warning - untested code ahead. Update fields/tables/variables where necessary.
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.insert();
}