- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2016 09:33 AM
Hi All,
I have created 2 tables, say A & B
Table A stores 'project_code;
Table B refers to this project_code & stores other values related to it like project amount & other values.
My requirement is when i delete that project code record from table A, its corresponding entries in table B should get deleted.
I am writing a 'before-delete' BR on table A(after delete does not fetch project code), it doesn't work.
Here is the code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var bill = new GlideRecord("u_project_billing");
gs.log('test'+current.u_project_code);
bill.query();
while (bill.next()) {
if(bill.get('u_project_code',current.u_project_code))
{
//bill.deleteMultiple();
bill.deleteRecord();
gs.log('test done');
}
}
})(current, previous);
Any help on this please.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2016 01:35 PM
I successfully tested this with the following assumptions:
1. This BR runs on table A, while the to-be-deleted records are on B
2. u_project_code is a reference field on Table B - to Table A
var bill = new GlideRecord("u_project_billing");
bill.addQuery('u_project_code', current.sys_id);
bill.deleteMultiple();
I also suggest to add to your Delete UI action an alert about the deletion of related records.
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2016 10:56 AM
Why current.u_project_code? If you are running it on Table A, then it should be current.sys_id.
current.u_project_code is the reference in Table B, no?
Harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2016 01:57 AM
no, it was the name of project code field in table A only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2016 12:55 PM
So, when a record is deleted on Table A, you want to go into table B and delete all records that is connected to it?
first, Think through if you really want to delete the records and not only inactivate them. Once they are gone, they are gone. Can't do any reports etc. on them
Looking at your text. I take that "u_project_billing" is Table B. And the filed "u_project_code" is the reference field on Table B to Table A
then your code should look like this *Not tested*
var bill = new GlideRecord("u_project_billing");
bill.addQuery('u_project_code',current.getUniqueValue());
bill.deleteMultiple();
You don't need "query()" when going to deleteMultiple and don't either need to do a while loop or something.
//Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2016 01:35 PM
I successfully tested this with the following assumptions:
1. This BR runs on table A, while the to-be-deleted records are on B
2. u_project_code is a reference field on Table B - to Table A
var bill = new GlideRecord("u_project_billing");
bill.addQuery('u_project_code', current.sys_id);
bill.deleteMultiple();
I also suggest to add to your Delete UI action an alert about the deletion of related records.
harel