Sage CRM - Capture entity event update? - sage-crm

Can i alter/intercept the event when updating an entity?
For example, for when i update the company entity?
The idea is to delete somehting in the BBDD after the entity is updated

You can use Table Scripts to run functions when a record is inserted, after a record is inserted, when a record is updated, or when a record is deleted.
Table Scripts use JavaScript, but have access to the server-side functions (such as FindRecord, SQL statements, etc).
So, you can add a Table Script to the Entity to delete a record via a SQL statement when a record is updated.
It's difficult to give you an example without knowing exactly what you're trying to do though.
Six Ticks Support

Related

In symfony what event can I use to add parameter to every database query?

I can’t find a solid answer for this, I’ve thought about using event listeners but I can’t seem to find a doctrine event to do what I want.
So the system we are building has different user accounts where each user is able to create a record, let’s say they can create a task using a Task entity and they can create a calendar event using a CalendarEvent entity.
Both entities have $createdBy mapped to the User entity.
When we pull data from the database, say a list of tasks, we only want the tasks for the current user but this would mean for every single entity in the system we would have to make sure the user is passed in the database query which easily becomes a mess.
What I want to do is automatically fill the $createdBy during persist and automatically add it as a where parameter during retrieval.
So instead in every repo function we write doing this for example:
$this->findBy([‘createdBy’=>$user]);
The createdBy part should be added automatically ; perhaps with some doctrine event?

Why does a DLookup in a Before Change data macro sometimes return an old value?

I have a large relational Access 2010 database. It is normalized, and includes some union queries that are very slow. I therefore thought I could speed things up by creating some cached fields. For example in tblOrder I would create a CustomerName field. To maintain this cached field I created a Before Change data macro that would dLookup the customer's company name from tblCustomer. It worked great. Then I created an After Update data macro in tblCustomer so when the user changes the Company Name all the child records would automatically be updated. It worked, but then the Before Change data macro fired and the dLookup returned the old Company Name. Any help would be very appreciated.
I made a sample of my problem using the Northwing Database. You can download a copy of it at http://www.thetechmentors.com/freestuff/exerciseFiles/msAccess/DlookupDatamacroProblem.zip
All you need to do is tweak the Before Change data macro on [tblOrder] to do the name lookup only when the [CustomerID] changes in that table. You can do that using the Updated() function like so:
That way when the macro fires as a result of the update performed from the After Update data macro on [tblCustomer], the [tblOrder].[CustomerID] value has not changed so the name lookup is bypassed.

Razor MVC - Object Edit Field Change Log

Users modify a DB object in an edit form that I have, pretty straight forward.
I need to implement a 'change log' on this object. I need to record which fields where changed and what they were before and after. I'm using Razor MVC.
I've done this by writing triggers for the table on update/delete. On update/delete of a record, the trigger pushes the record to a History table, in a History database. This creates the change log. Then you would just need to display it; to identify the change would require evaluating each and every field.
There's nothing already built that wold do this for you that I know of.

updating batches of data

I am using GridView in asp .net and editing data with edit command field property (as we know after updating the edited row, we automatically update the database), and I want to use transactions (with begin to commit statement - including rollback) to commit this update query in database, after clicking in some button (after some events for example), not automatically to insert or update the edited data from grid directly to the DB...so I want to save them somewhere temporary (even many edited rows - not just one row) and then to confirm the transaction - to update the real tables in database...
Any suggestions are welcomed...
I've used some good links, but very helpful, like:
http://www.asp.net/learn/data-access/tutorial-63-cs.aspx
http://www.asp.net/learn/data-access/tutorial-66-cs.aspx
etc...
Well,
you can store your edited data in a DataTable in session. and then pass this data table as a bulk insert in to the database. 2 options are available for this
if you are using SQL Server 2005 you can use OpenXML to achieve this, as i have stated here
if you are using SQL Server 2008 youc an use Table Variables like i did here.
i hope it helps
First way:
Create session variable that will contain your DB object (DataTable or mapped objects).
The GridView should work with this instance instead of sending the data to the database.
Once editing is finished you may take the object from the session and save it in the way you normally do.
Second way:
I would use javascript to collect all changes on the client side while he is editing as a array of objects (each object is separate row).
Once the editing done, you can create json string from the collection and pass it to the server.
If your json object configuration is same as server class then you can use JavaScriptSerializer to deserialize your string into collection of object.
After that, you can save your objects in the way you normally do.

Linq update problem

I have an application with user and admin sections. If an admin updates data with the help of sql datasource then it's updated the database. However, when we retrieve data with linq query then it's showing its old value rather than the updated value.
After some time, the linq query automatically shows the correct value.
I think its caching the value, but I find myself helpless. Please help me with this.
When you say
when we retrieve data with linq query
Do you mean you call your select methods again or are you using the current in memory objects?
In either case, you can always refresh an entity with :
Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, entity)
Make sure that you're using your DataContext efficiently (ideally one per unit of work).
After each update, make sure you call DataContext.SubmitChanges(); to commit your changes back to the database.
Also be aware that any context you instanciate between your changes being added to another context and calling SubmitChanges() will not reflect those changes.

Resources