create multiple records via script

RudhraKAM
Tera Guru

we have 5 records in table A based on these records we need to grab some details from this  record and create another contract record (via schedule job ) can someone help me with the code 

 

Table A record contains: Short description , user ID , Start date 

 

We need to grab each record in Table A and Create a record by copying Short des  to Short dec , User ID to User ID etc via schedule job and once the record is created in Table B we need to set the state in Table A record as Completed.

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, can you be more specific about your requirements IE why do you need to use a scheduled job, what type of record is table A - a task extension? Running any sort of conditional filter query using free text fields like short description is both inefficient and prone to user induced failure.

As far as code goes, you will learn more if you attempt this yourself and post your script for review\assistance as required.

View solution in original post

3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, can you be more specific about your requirements IE why do you need to use a scheduled job, what type of record is table A - a task extension? Running any sort of conditional filter query using free text fields like short description is both inefficient and prone to user induced failure.

As far as code goes, you will learn more if you attempt this yourself and post your script for review\assistance as required.

var grCIServer = new GlideRecord('u_loto');
grCIServer.addEncodedQuery('u_state=new');
grCIServer.query();
while (grCIServer.next()) {
    var grc = new GlideRecord('u_contract');
    grc.initialize();
    grc.date = gs.nowDateTime();
    grc.amount = grCIServer.amount;
    grc.short_description = 'MOTO SERV' + grCIServer.u_service_name;
    grc.insert();

    grCIServer.u_state = 'completed';
    grCIServer.update();
}

Assuming u_loto is an extension of the task table?
then the state field will be 'state' not 'u_state' and it's value numeric not 'text'
IE the default 'Closed Complete' state value for most task tables is 3

grCIServer.addEncodedQuery('state=1');
grCIServer.u_state = 3;

Otherwise, without specific details of your configuration, the forum can only guess at your configuration and any resulting issues.

What are the results of your debugging\diagnostics?

Is u_contract extended from an existing table?
if it is not an extension, short description is probably u_short_description

Similarly if the 'amount' field is a custom field in either table?
then perhaps it should be referenced as u_amount?