I have tried to see if there is already a post like this, but cant seem to find anything. Apologies if i have missed one
I have the app set up to email a department, when a record is added. They also get an email when its edited. both of these use the page submit rules. I would like to also send an email if its deleted, but as this isn’t done by a page submit, its not possible currently. Speaking with support, they said to look at custom code, so i guess here i am, hoping that someone has done something similar and can offer some advice? anything.
Just to update, im currently running the code below, to ask the user to email the concerned department, and giving them the record ID to include:
$(document).on(‘knack-record-delete.view_56’, function(event, view, record) {
alert('You have removed this role. Please inform ORD. You should include the record ID (used by ORD), which is: ’ + record.id);
});
However as all other forms do the email for them, this leaves me open to problems (they miss the alert or are just too lazy to send it etc).
Looking around online, it doesnt look like i can send an email from javascript directly. Im still hoping to find some way of triggering an email automatically.
Thanks for coming back to me on this. I have read through the attached, and i admit im a little lost here.
If im understanding this correct,
I create a form that loads the record being deleted, and sends its info via email
i then call that form via the api using the javascript for on delete?
this should then delete the record, as well as send the email, without the user seeing the form?
would the form not fail, if the record is being deleted prior to the form?
apologies, but im not sure i grasp the concept here
Let me start by saying, you are amazing! this works, and is exactly what i’m after.
one problem i have with it. the fields that are ‘connections’ don’t seem to go through. All the date fields, short text fields etc go through and i seen a newly created record in the new object.However the fields that are ‘connections’ are blank.Do i have to do something different with them? In the new object, i have set them up as connections the same as the first object. Does the script need anything additional for connected fields?
The code is below:
$(document).on(‘knack-record-delete.view_56’, function(event, view, record) {
var data={};
data.field_340= record.id; //id
data.field_328= record.field_142; // connected field
data.field_329= record.field_143; //connected field
data.field_330= record.field_144; //date field
data.field_331= record.field_145; //date field
data.field_332= record.field_147; //Short text field
data.field_333= record.field_148; //Connected field
data.field_336= record.field_169; //Connected field
data.field_337= record.field_170; //Connected field
data.field_338= record.field_238; //Connected field
Bonus question: is there a way to get the code to monitor two views? Currently it is looking at view_56 but i would also like it to look at view_92. I guess i can copy the entire code, with the change, just wondering if there is a better way to do it?
Im sorry, i think i may be out of my depth here. The code isnt running at all in the browser, as it gives that error. Nothing is being moved to the new object when deleting now. When i inspect via the browser it points me to that line as the problem.
okay, so i have been playing around with it and found i just needed to do it on the second part, ie:
data.field_328= record.field_142_raw[0];
This seems to work, however it doesnt work for the conenctions to the user accounts. two of the fields are connections to users accounts.
when i try 336[0].id or 336_raw[0].id i get errors in the console.
when i place [0].id on the fields there being copied from i get undefined, but if just have _raw[0] (as below), the data appears in the console, but isn’t being place in the object.
a record is being created with the all the information in the ‘deleted’ object, just the two connected fields for users is staying blank, even thought the correct id / identifier is being placed into the data?
I really appreciate your help with this, id be very lost without you!
that is the way i have it currently. field 336 and 337 are for the new ‘deleted’ object. Field 169 and 170 are from the original object, where the item is being deleted from.
if i put [0] .id or .id after 169 or 170 i just get undefined in the console. But if i put _raw[0] after them i get the data appear in the console. it just doesn’t make it to the object, along with the other fields for some reason.