Reputation: 1442
I need to delete some records related to the current record when it is deactivated. I can get the the event when the record is deactivated but I have looked around for some time on Google and this site for the code to delete records in javascript but I can't find any, though I know there must be some out there.
Can anyone help?
Thanks
Upvotes: 0
Views: 833
Reputation: 17562
If you really want to delete a record with JavaScript there is a sample on the MSDN.
Its a little long winded (its a CRUD example - create, retrieve, update & delete). But it should contain the information you need.
Note there is also an example on that page which doesnt use jQuery (if using jQuery is a problem).
That said I think for this operation would will find it easier to implement, test and maintain with a plugin (so I would go for Greg's answer).
Additionally a plugin will apply in all contexts, e.g. if you deactivate the record in a workflow your JavaScript will not run, but a plugin will.
Upvotes: 3
Reputation: 3878
I would be alright with doing this with a plugin, all I would need to know is how to pick up that the record has been deactivated
You can register a plugin on the SetState
and SetStateDynamic
messages (recommend the Pre event in your scenario). Each of these messages will pass an EntityMoniker
in the InputParameters
property bag which refers to the record that is being deactivated.
In your code you will need to:
EntityMoniker
from IPluginExecutionContext.InputParameters
SetState
transaction to completeUpvotes: 3