Page 1 of 1
after update hook
Posted: 2017-06-13 00:53
by bescott53
I have tried unsuccessfully with this, any help would be appreciated.
I have a table called wdcd_WDCD, in this table the primary key is SFRefNum. what I am needing to do is when someone updates a record that a check is made against the table, if there are other records with the same OpID then the update that was made is also copied over to those other records. I need the following fields updated, WDCD, ICV, WDCDVALUE, NOTES, LASTEDITEDBY, LASTEDITEDON, CLOSEDATE, SPECFORECASED, SLT, SEB, APPROVAL, SECSPEC, SECSOL.
Hope this makes sense,
Re: after update hook
Posted: 2017-06-13 22:08
by AhmedBR
I usually use something like this:
Code: Select all
sql("update `wdcd_WDCD` set WDCD= {$data['WDCD']}, ICV= {$data['WDCD']} etc.....
where `OpID ` = {$data['OpID ']}", $eo);
Might not be the most elegant way, but works fine for me.

Re: after update hook
Posted: 2017-06-15 07:05
by bescott53
Thanks AhmedBR, I have tried this but when I save a record I get a blank screen, not sure if its connected. It was fine before. I removed and issue still there, any ideas?
Re: after update hook
Posted: 2017-06-16 14:16
by bescott53
ok, the blank screen is definitely down to adding in the sql to the hook. I moved it to appear after the return TRUE; and all ok, with one exception, it doesnt do what I need, it is not updating the other records? any help on this would really be appreciated
Re: after update hook
Posted: 2017-06-17 19:29
by AhmedBR
When you get a blank screen, use the mouse and select "View Page Source" this will show you what is causing this blank page.
Usually an error in your MYSQL statement.
You did not copy the code as is from here, right?
(the code is just an example to what you should do, you need to complete it, that is remove etc.... and right the other fields and double check the column names as in your database)
Re: after update hook
Posted: 2017-06-19 09:26
by bescott53
Thanks for helping Ahmed, I really appreciate it.
here is the error:
<script>
$j(function(){
show_notification({"message":"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' WDCDValue= , Notes= test, LastEditedBy= bescott53, LastEditedOn= 2017-06-16 13:' at line 1<pre>Query:\nUpdate `wdcd.wdcd_WDCD` set WDCD= , WDCDValue= , Notes= test, LastEditedBy= bescott53, LastEditedOn= 2017-06-16 13:38:41, SLTSponsor= Luke Beeson, SEBadged= , , CloseDate_SpecialistForecasted= , ApprovalType= , SecuritySpecialist= , , SecuritySolution= where `OpportunityID ` = <\/pre><i class=\"text-right\">The above info is displayed because you are currently signed in as the super admin. Other users won't see this.<\/i>","class":"danger","dismiss_seconds":7200,"dismiss_days":0,"id":0});
})
</script>
and the actual line is this:
sql("Update `wdcd.wdcd_WDCD` set WDCD= {$data['WDCD']}, WDCDValue= {$data['WDCDValue']}, Notes= {$data['Notes']}, LastEditedBy= {$data['LastEditedBy']}, LastEditedOn= {$data['LastEditedOn']}, SLTSponsor= {$data['SLTSponsor']}, SEBadged= {$data['SEBadged']}, CloseDate_SpecialistForecasted= {$data['CloseDate_SpecialistForecasted']}, ApprovalType= {$data['ApprovalType']}, SecuritySpecialist= {$data['SecuritySpecialist']}, SecuritySolution= {$data['SecuritySolution']} where `OpportunityID ` = {$data['OpportunityID ']}", $eo);
Re: after update hook
Posted: 2017-06-19 12:56
by AhmedBR
I believe the error is in The table name: `wdcd.wdcd_WDCD` should be `wdcd_WDCD` or the correct name of your table. check it out and see if this solves the problem.

Re: after update hook
Posted: 2017-06-19 13:15
by bescott53
OK table names is right now (wdcd_WDCD) but still getting error?
<script>
$j(function(){
show_notification({"message":"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' WDCDValue= , Notes= test, LastEditedBy= bescott53, LastEditedOn= 2017-06-15 09:' at line 1<pre>Query:\nUpdate `wdcd_WDCD` set WDCD= , WDCDValue= , Notes= test, LastEditedBy= bescott53, LastEditedOn= 2017-06-15 09:30:09, SLTSponsor= , SEBadged= , , CloseDate_SpecialistForecasted= , ApprovalType= , SecuritySpecialist= , , SecuritySolution= where 'OpportunityID' = OIJ-0876123<\/pre><i class=\"text-right\">The above info is displayed because you are currently signed in as the super admin. Other users won't see this.<\/i>","class":"danger","dismiss_seconds":7200,"dismiss_days":0,"id":0});
})
</script>
Re: after update hook
Posted: 2017-06-19 22:12
by AhmedBR
I can see two possible problems: too many null values, and some results with nothing between comas!
Let´s narrow things down (this is my simple way of solving these kind of problems):
Use JUST the following in your hook (do not forget to double check table and field names in my formula):
Code: Select all
sql("Update `wdcd_WDCD` set LastEditedOn= {$data['LastEditedOn']} where `OpportunityID` = {$data['OpportunityID']}", $eo);
Does it update correctly?