Home › Forums › Modern DFFS › Stop saving using dffs_PreSaveAction
- This topic has 5 replies, 2 voices, and was last updated 4 weeks, 1 day ago by
Alexander Bautz.
-
AuthorPosts
-
-
January 15, 2025 at 06:47 #38376
Hi Alex,
I have a requirement in which i need to create a new record in a different list (lets call it LIST-B) from LIST-A. My current rule setup is as follows in LIST-A:
Rule-A
Trigger based on field change. Checks if a particular field is “Yes” and is changed from initial value. If true, then the action is to prepare an email and then call a function that flags a variable (VARIABLE-A) to true.In my dffs_PreSaveAction, i am checking if VARIABLE-A == true and if it is then call a function to create the new record in LIST-B with some data from LIST-A. This function is an async function. So i am using the .then().catch() pattern. Depending on the response from the record creating function, i am either returning true, or false (to stop saving). However, no matter what I do inside the then() or catch(), I am not able to stop the form from saving. I am guessing this is due to the new record creating function is async. If that is the case, what are my options to achieve my requirements?
My new record creation function also sets a global variable (newRecordUrl). This is the url of the newly created record. Will setting the variable here work, if the “prepare email” action is using the [[variable:newRecordUrl]] in Rule-A? If this is not possible, what are my options for such requirements?
Greatly appreciate all your help.
Thank you! -
January 15, 2025 at 16:36 #38378
Hi,
Can you attach the relevant code as a txt-file? – please ensure you strip away any sensitive information.Alexander
-
January 15, 2025 at 16:58 #38379
I have attached a word document. Hopefully this helps.
Attachments:
-
January 15, 2025 at 21:36 #38381
Try it something like the attached code. I have butchered your code a bit so you must edit it to match what you wanted to do after the child list item has been created. See comments in the code and let me know if you have any questions.
Alexander
Attachments:
-
January 17, 2025 at 16:02 #38387
Hi Alex,
This worked great. Instead of preparing the email during a rule, i had to create another rule that prepares the email. This rule had to be triggered from custom javascript. I called this rule after child item was created successfully. This way, the email had the newRecordLink variable populated and available.
Thank you so much for your help.
-
January 17, 2025 at 16:40 #38388
I’m glad it worked.
Alexander
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.