On Wakanda Server, how can I access the current value of an attribute during a save / validate? - wakanda

I am building a "change log" feature for a Wakanda application. During the validate or save events on the server, I need to get access to the existing value of the attribute as it is in the datastore so I can record a before value and an after value.
At this point, the only solution I have found is to run a query in the validate event and retrieve the entity fresh from the datastore. Perhaps this is the best / only solution?

Yes, the solution is to run a query in the validate event.
In the validate event function the word "this" refer to the new entity that will be saved.
You can get the existing entity by running the query (find()) :
ds.Item.find('ID = :1 ', this.ID);

Related

Set a field value directly from an asyncValidate result

I have a form where a user enters an Id into a text field, and I then I validate said Id on the server. If the Id does not exist in the system, I display an error. I do this using async validation. If the Id does exist, however, the server will return a record from our database. I want to use those values to auto populate other fields in the form.
How would I accomplish this?
I did some searching and the closest solution I found was this other question on StackOverflow. The thing is, I want to change the value after my asycValidate logic has succeeded. I don't think I can trigger the action creator from inside asyncValidate, and I'm not aware of a way to have asyncValidate trigger a callback from inside the form component.
I was able to get it to work, by following the solutions discussed in the following thread: https://github.com/erikras/redux-form/issues/442

Simple private messaging system. How to mark as read

I'm building an app in Laravel, and using the eloquent ORM.
i want to create a simple private messaging system within my application. Nothing mad complex. It will basicaly be like email. It has a recepient, title, content and timestamps.
I want the ability to show if it's read/unread. Would having a column as a boolean called 'read' which has a default value of 0 work. When the user clicks on it, the read attirbute changes to 1, and the message is marked as read.
How would I update the attribute, when the message is opened.
Laravelish way, is to use a column named read_at, and set it to NULL if unread, and the current timestamp when read.
Migration part of read_at may look like:
$table->timestamp('read_at')->nullable()->default(null);
Note: do not forget to add read_at to $dates array so working with read_at is easy - carbon way.
If you are not using front-end framework like Angular or react, make ajax request to your controller function. In controller function update the db table using ORM or Query Builder. Using Ajax you can do it without affecting to the user view.
if you are making simple messaging system, store a flag with read. When the user clicks on a message, take that message's id and update that records read with 1 and unread 0 using an update action.

Square Connect API V2: Partial updates to catalog objects?

In the V2 api, is there a way to partially update a catalog object? For example, if I have an item, and I don't want to keep track of modifier_list_info, it seems I have to send that data with any upserts otherwise it will get wiped out.
Is there a way to specifiy a partial update?
The best way to update a catalog object would be to first retrieve the object (https://docs.connect.squareup.com/api/connect/v2#endpoint-retrievecatalogobject), and then edit the properties you need to change. For instance, the response will have an object field so
response.object.item_data.name = 'Food'
will change the name to 'Food'. Then pass the entire object back to the UpsertCatalogObject endpoint. This will keep all the same properties except for changing the name.

KendoUI grid create : how to deal when server response only the id of the new created item

I want to use the KendoUI grid widget with a rest API (manage by dreamfactory); when i create a new item with the grid the server response contains only the new id and NOT the fully new item (aka all the fields) as I read in this forum http://www.telerik.com/forums/request-for-support-on-editable-grid#2098471.
"When you add a new item in the Grid its ID should be generated on the server and the newly inserted item (as an array) back to the client. This way the DataSource can update its internal data and the Grid widget will update the column for this field. In case the server does not return the result, the inserted item will be treated as a new one every time you sync the dataSource. The same applies for destroy and update functionality."
My question is how to deal with if we cannot modify the contains of the server response.
here is the response i get from the server : {"record":[{"id":26}]}
Any idea?
According to the DreamFactory documentation, only the id of the created record is returned by default. The docs also mention that you may select the returned fields. Using fields=* will return all created fields. You should be sure to use the record wrapper to force the return of an array rather than a single, unwrapped id field.

MS CRM Save + Copy as new (Custom Entity)

I have a custom entity in Microsoft CRM (4.0). The user has to input records however usually they have a batch of 20+ records that are almost the same apart from 2 or 3 fields which need changing. I know I need to write some custom code to enable this functionally. However can anyone recommend any methods to do this.
Ideally there should be a button that will save and create a copy as a new entity.
My Current way of thinking is to pass all the details as part of the URL and use javascript to strip them out on the page load event. Any ideas welcome.
Thanks
Luke
I found the answer here:
http://mscrm4ever.blogspot.com/2008/06/cloning-entity-using-javascript.html
I've used it and it appears to work well.
Since there are numerous fields, but only certain fields values are different, then i am thinking to set the default value to all the fields, so that users just need to alter those values when needed.
In my approach, i will hook a javascript function on load of the form data entry screen and use XmlHttp approach/Ajax approach to hook to the custom web service to pull/retrieve the default values of each fields. Or you can set those values at the javascript function itself, but the drawback of this, it's difficult to customize later. So i will choose the approach to hook to the custom web service and retrieve those value from some application parameter entity.
Your idea of providing a "clone" button is also a great idea, which means that it will duplicate all the attributes of the previous record, into a new record, so that it will save time for data entry person to customize the different value
EDIT
Since you would enter records in batch mode, how about customizing .ASPX screen to enter records. By customizing through .ASPX screen, you can use a tab , so that users can browse through tabs, to customize the value/attribute of each record.
There will be a "save" button as well as "clone" button to clone some common attribute or value.
I would create a custom web service that would accept the entity type and the ID of the record I'm cloning. Your "Save and Clone" button would call the service, and the service would handle the details of retrieving the current record and deciding which fields to set on the new record. The service creates the record, and sends the Guid of the record back to your button, which then opens up the newly created record.
This way, you avoid the messiness of setting/getting values in JavaScript and tying which fields to set/retrieve directly to your OnLoads, as well as avoiding the possibility of query string that's too long.
The service could easily be sufficiently generalized so that all you'd have to do is add your button to any entity, and it would work, assuming you'd set up your service to handle that particular entity.
One possible downside is that since the clone record button would actually create the record, the user would be forced to delete the cloned record if they decided they didn't want to clone the record after all.

Resources