How to create records using a script?

christiancardos
Kilo Expert

Hi experts,

I have this idea, could you help me for how make this?

A = (u_fecha_de_inicio)       type: date

B = (u_horas_mes)                     type: decimal

C = Records, within of this record exist the variable   = (u_horas_mm)

D = (u_horas_totales)             type: decimal

well, should be created records depending of the following:

Should be created records depending on the variable B, in this case contains the number 20, so you should create records with that value in the variable (u_horas_mm),

until those values for each independent record, added all become equal to the variable D, in this case 400.

With this what it would look for is to make the records as are necessary until all a up to what it contains D.

find_real_file.png

Thanks   and Regards!

CC

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

If I get what you are saying, you want child records created automatically for all the total contracted hours.   For example, your company contracted us for 400 hours at 20 hours per month?



after insert of the parent service contract:



var hours = current.u_horas_totales;


var hpm = current.u_horas_mes;


var count = hours/hpm;



for(i=0; i<count;i++){


var child = new GlideRecord('child_table');


child.contrato = current.sys_id;



child.insert();


}



That would create 20 blank records all relating to the parent contract.   You can add info as needed.


View solution in original post

1 REPLY 1

Mike Allen
Mega Sage

If I get what you are saying, you want child records created automatically for all the total contracted hours.   For example, your company contracted us for 400 hours at 20 hours per month?



after insert of the parent service contract:



var hours = current.u_horas_totales;


var hpm = current.u_horas_mes;


var count = hours/hpm;



for(i=0; i<count;i++){


var child = new GlideRecord('child_table');


child.contrato = current.sys_id;



child.insert();


}



That would create 20 blank records all relating to the parent contract.   You can add info as needed.