- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 06:02 AM
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,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 06:47 AM
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();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 06:06 AM
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().)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 06:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 06:27 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2017 06:07 AM
Is your script running , check either log is printing.
Regards,
Harish Murikinati.