Facing issue with creating a new record using gr.initialize() ,gr.newRecord()

Community Alums
Not applicable

Hi All,

I have created one custom table A (which is not extending any table), and also I have created one another table B (which is extending task table).

Now when even a new record created on table A i want to create a new record on table B with reference fields values is table A's sys_id. I have tried to use the below script for creating new record, but no record is creating on the form.

gs.log("executing busines rule", "Swamy");

var gr = new GlideRecord('u_data_discovery_task');

gr.initialize();

gr.short_description = 'New incident 1';

gr.u_cloud_migrations = current.sys_id;

gr.insert();

When I used gr.initialize(), I could not see any record created on u_data_discovery_task table. So I have used gr.newRecord() instead of gr.initialize().

gs.log("executing busines rule", "Swamy");

var gr = new GlideRecord('u_data_discovery_task');

gr.newRecord();

gr.u_cloud_migrations = current.sys_id;

gr.short_description = "Please completed the application "+current.u_application_name.getDecryptedValue();

By using gr.newRecord() I am getting the sys_id of created record, But i could not see record created on u_data_discovery_task table. So I thought that record is not saving on the form. So I tried to update the record by giving gr.update() as shown in the below script, But no result.

gs.log("executing busines rule", "Swamy");

var gr = new GlideRecord('u_data_discovery_task');

gr.newRecord();

gr.u_cloud_migrations = current.sys_id;

gr.short_description = "Please completed the application "+current.u_application_name.getDecryptedValue();

gr.update();

All the time I am getting the log which i mentioned in the 1st line of the script.

Could anyone tell me what I am missing ? why my script is not working, why record is not creating ?.

Note : Initially I have created the Before, After business rule to create the new task record, when even i submitted the record on table A, the form is saving and not available for me. So i have created the async type business rule. I can see the there is no delay in saving the form. But backed record is not creating.

Thanks for your response,

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

There might be a business rule on 'u_data_discovery_task' which is aborting the insert. Use setWorkflow(false) and see if it works. If it works then you know who the culprit is. Use this code



var gr = new GlideRecord('u_data_discovery_task');


gr.newRecord();


gr.u_cloud_migrations = current.sys_id;


gr.short_description = "Please completed the application "+current.u_application_name.getDecryptedValue();


gr.setWorkflow(false);


gr.insert();


View solution in original post

7 REPLIES 7

Chuck Tomasi
Tera Patron

Your record is not saved until you do a gr.insert() or gr.update().



The main difference between gr.initialize() and gr.newRecord() is that, while both create an object (or space), newRecord() sets default values (including generating a sys_id BEFORE the record is committed to the DB with insert() or update().)


See episode 29 from the TechNow list. Start around the 3:50 mark.



TechNow Episode List


Community Alums
Not applicable

Hi Chuck Tomasi,



Thanks for your response,



I have user gr.insert() and gr.update(). But in both cases record not created in table B. am I missing anything in my script. Could you please tell me what the mistake i am doing.



Thanks,


Swamy


Harish Murikina
Tera Guru

Is your script running , check either log is printing.



Regards,


Harish Murikinati.