Jump to content
  • 0

Triggered Action Not Working


SydneyH

Question

I have a triggered action setup with the goal of replacing the "Account Balance" in one table, based on entry into the other table. The triggered action is currently setup to add the newly deposited amount to the existing balance. The task validates but won't populate the data as intended unless I remove the "addition problem". If the task is set to update 'Account Balance = #inserted.DepositAmount' it will run successfully. Has anyone else experienced this issue? I have  nearly identical tasks within other tables of my application that function as intended with subtraction of similar variables. 

image.png.8b8087333495e8edf9e8c3025734dedc.png

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Hello @SydneyH,

Is the 'AccountBalance' field blank initially?

If yes, this means that it stores NULLs. And when we add anything to NULL the result is NULL (blank).

This NULL should be replaced by zero:
gL8SriQ.png

Do you need to run this Trigger on Update as well? I can see the 'Update' action on your screenshot but in the text, you only describe the 'Insert' action (adding new entries).

Please note that the logic on Update is different. If you need assistance please let me know.

Link to comment
Share on other sites

  • 0

Thank you for explaining this so thoroughly.

I believe we can run the trigger on Insert only, vs. both insert and update. We are tracking each deposit as its own line item upon entry/insert. The starting balance for every new participant is always 0, which is likely where my problem was considering the 'case' logic was not implemented. This fixed our issues. Thank you so much!

 

-Sydney

Link to comment
Share on other sites

  • 0

I have a similar problem

I have a table the holds the agregate data of dried coconut from a number of growers who delivered bags of green Coconut to the processor.

For each batch we have multiple delivery receipts from the grower with the number of bags and the total weight in kg of green copra.

In the grower purchase table for every receipt entry I need to add the weight and the number of bags to the batch total green weight field in the batch table.

The index field is the batch id.

I have been working on triggered actions for a week and still can't get it 

So the trigger should be 

Insert a new record in the grower purchase table and ad the weight from the weight field to the total green weight field in the batch table for each record  where the batch id is the same

So I get the sum of the weights for all receipts with the same batch number.

image.png.8e18c82aed05b28ad1592b99cc84cd5c.png

I think I am missing something

 

Link to comment
Share on other sites

  • 0

@Corpcatalog, I think you are simply missing adding the current NetworkBatch.TotalGreenWeight with the Growerpurchase.Weightkg.

So instead of TotalGreenWeight = Growerpurchase.WeightKg + 1, it would be TotalGreenWeight = NetworkBatch.TotalGreenWeight + Growerpurchase.WeightKg.

To explain a little further, the setup you shared is replacing the TotalGreenWeight value with whatever was just inserted with Growerpurchase.WeightKg and adding 1 to it. If you want to have a running sum, you need to take the value that is already in TotalGreenWeight and add the new Growerpurchase.WeightKg to it. This should take what was originally in TotalGreenWeight and adding the new weight to that, instead of replacing it with the newly added weight + 1.

Also, you don't need to do a JOIN and use the WHERE clause to select the correct record with BatchID. Since you are already limiting the records to match with an index field in the JOIN, you don't need to use WHERE because only one record should be selected. I'd try getting rid of the WHERE clause as well as the update above. 

Link to comment
Share on other sites

  • 0

#inserted is the way to go. Is it not updating at all, or are you getting the wrong number?

First, make sure your trigger is on the correct table. It needs to be on the same table as the datasource for your submission/report page where you are inserting the new record.

Try switching out the JOIN with the WHERE block - Since you are already using the insert trigger on Growerpurchase (I assume), those records should already be selected. And, since the UPDATE block is for the NetworkBatch table, those are already selected. I don't think you need the JOIN it again, just use the WHERE clause.

Make the WHERE clause = #inserted.BatchID equals NetworkBatch.BathID

Link to comment
Share on other sites

  • 0

Hi KP

Ok first thing I worked out I was actually using the wrong field 

The correct field for the table receiving the data is BatchNo However I tried what I think are all the possibilities and it still didnt add anything to the field

The Batch file looks like 

image.thumb.png.7aff19a21c71bd89a5f8b21011240002.png

 The Growerpurchase file looks like 

image.thumb.png.d1b196cafd81d5e7b732273e8d3d21e6.png

The current triggered action I have in the above table is, which still doesnt work - I tired it with difference join and with and without where clause and joining the table or joining just the inserted records.

image.thumb.png.294a71dc34674b8fd171e4ede8122335.png

 

I Find triggered actions to be a very clumsy way to work. Ive been using caspio for 12 years and shy away from using the triggers when I build an app because I invariable can't get them to work.

Link to comment
Share on other sites

  • 0

Just a couple things to be clear - 

The trigger is on the Growerpurchase table, right?

And, you are testing this out with new records, correct? An insert trigger will not update past records, as in it will not go back and update the TotalGreenWeight field with WeightKg from prior records. That would need to be done using a Task.

Link to comment
Share on other sites

  • 0

Yes the trigger is in the Growerpurchase table and I am adding a new record in the growerpurchase table, the primary and foreign key for this record is the batchno

ORG-030223-STMW-19, for example for the last record in the table.

As I understood from watching the video, everytime I add a record to the growerpurchase table I can get the trigger to add the weight to the record with the corresponing Batchno in the Batch Table.

If not what is the point of triggers in one to many relationship tables?

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...