insert and delete a record from one table to another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 03:05 AM
i have created 2 tables 1.sales_lead
2.u_dupl_lead
i have created one checkbox in "sales_lead", when i check this checkbox, automatically record should delete from "sales_lead" and insert into "u_dup_lead".
but here problem is record was inserted into " u_dup_lead" but not deleted from " sales_lead".........
Here is my script.
Table: "sales_lead"
AFTER, INSERT, UPDATED.
SCRIPT:
if(current.u_archive_now==1)
{
var gtt=new GlideRecord("u_duplicate_leads");
gs.addInfoMessage("inserting...");
gtt.u_dup_archive=current.u_archive_now;
gtt.first_name=current.first_name;
gtt.last_name=current.last_name;
gtt.account_name=current.account_name;
gtt.assigned_to=current.assigned_to;
gtt.insert();
var go=new GlideRecord("sales_lead");
go.addQuery('sys_id',current.sys_id);
go.query();
if(go.next())
{
gs.addInfoMessage("deleteing");
go.deleteRecord();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 03:25 AM
Hi Kishore,
try using this code
if(current.u_archive_now==1)
{
var gtt=new GlideRecord("u_duplicate_leads");
gs.addInfoMessage("inserting...");
gtt.intialize();
gtt.u_dup_archive=current.u_archive_now;
gtt.first_name=current.first_name;
gtt.last_name=current.last_name;
gtt.account_name=current.account_name;
gtt.assigned_to=current.assigned_to;
gtt.insert();
if(gtt.next())
{
gs.log('deleting');
var go=new GlideRecord("sales_lead");
go.addQuery('sys_id',current.sys_id);
go.query();
if(go.next())
{
gs.addInfoMessage("deleteing");
go.deleteRecord();
}
}
}
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 03:49 AM
Hi,
sorry , not working..
Records are duplicated.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 04:05 AM
Kishore,
Create OnAfter Business Rule:
in Condition : current.u_archive_now==1
Var dup = new GlideRecord('sales_lead');
dup.addQuery('sys_id', current.sys_id);
dup.addQuery('active', true);
dup.query();
if(dup.next())
{
dup.deleteRecord(); // delete the records.
gs.log('deleted the record');
var gtt=new GlideRecord("u_duplicate_leads"); // start inserting the records.
gs.addInfoMessage("inserting...");
gtt.intialize();
gtt.u_dup_archive=current.u_archive_now;
gtt.first_name=current.first_name;
gtt.last_name=current.last_name;
gtt.account_name=current.account_name;
gtt.assigned_to=current.assigned_to;
gtt.insert();
gs.log('inserted the record');
}
}
Can you please check this now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 04:25 AM
Deleted and re-created in both side
sales_lead and u_dup_lead...
i have tyried with my code again same.....
in sales_lead table-u_dup_lead record are creating..