Adding script to add records in table

Ajinkya Avinash
Giga Contributor

Hi I have one Major table Reports I have 4 Related list for the same table,  whenever any record gets inserted in Reports table i want to add respective number of records in related list tables as well

I have written below script

 

for(var i = 1;i<5;i++){
var gr = new GlideRecord('u_a1');
gr.initialize(); //this will create an empty record to populate before an insert.
gr.u_number_a1 = current.sys_id;// this will give the reference for the record
gr.setValue('u_sr', i);
gr.setValue('u_proffetional_category', i);
gr.insert();
}


for(var j = 1;j<5;j++){
var gr1 = new GlideRecord('u_a2');
gr1.initialize(); //this will create an empty record to populate before an insert.
gr1.u_number_a2 = current.sys_id;// this will give the reference for the record
gr1.setValue('u_sr', j);
gr.setValue('u_professional_category_a2', j);
gr1.insert();
}

 

I have kept u_professional_category choice list values are 1 2 3 and 4 as i want but its getting converted into float i am not getting why it is converted into a Float value.

Please help

5 REPLIES 5

Prateek kumar
Mega Sage

What type of fields are your u_proffetional_category and u_professional_category_a2


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Choice field

Hi Ajinkya,

Can you share the dictionary entry for those 2 fields and also their choice values?

can you set it as below?

gr.u_proffetional_category = i;

gr.u_professional_category_a2 = j;

Regards
Anku

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Please find dictionary entries for both fields in an attachment With Choice values