How to programmatically refresh a screen from onFinished callback function? - appconkit

e.g. we have this one guy calling server function for creating a new entity:
function loadData() {
var vServerController = mobileController.serverController();
var vJSONRequest = vServerController.createJSONRPCRequest();
vJSONRequest.setQueryMethod("createSomeNewElementBasedOnTwoIds");
vJSONRequest.addParameter("firstID", 1);
vJSONRequest.addParameter("secondID", 2);
vJSONRequest.setOnFinish(callBackOnFinish);
vServerController.addToQueue(vJSONRequest);
}
function callBackOnFinish() {
var vController = mobileController.activeController();
vController.showView(Screens.SomeScreen, true);
}
So how we can refresh a Screen after this call? The server will return not a full set of data but just a new one.
What is the best approach to doing this?

Assuming you want to update the currently displayed data, you have two options - and you propably don't need to use a callback for this
Replace the displayed dataset
Update the displayed record
(if you had user input or created a new entry) merge the entries
1: just return the data from the server with foundset.setDataMode(DataMode.REPLACE) - it will automatically refresh the displayed data. But In case you are working with multiple records for one entity and you only want to update one of them, use option 2.
2: Return only the specific record you want to update without datamode replace. The record is identified by it's key/id elements. You can find those marked with a little key symbol in the entity editor. So just make sure that those key elments and any additionaly elements you want are returned. The AppConKit will automatically merge the existing record with the data and display that.
3: If you created a new record on the device, that record will have a value called client_uuid. If you now return a record from the server that contains both the client_uuid AND the key element, the record created on the device will be merged with the server created record and the new record will displayed
Hope this helps!

Related

update One2many Record using Write function called from Onchange (Odoo10)

I am trying to update my One2many record when Onchange method is called. I am fetching the exact value but its not updating the field. Neither I am getting any error.
class abc_1(models.Model):
_name = 'abc.1'
field_a1 = fields.Many2one('crm.team',required=True)
field_a2 = fields.One2many('abc.2', 'field_b1')
#api.onchange('field_a1')
#api.depends('field_a1')
def get_records(self):
for res in self.field_a1.member_ids:
print res.name
self.write({'field_a2':(0,0,'field_b2':res.name})]})
class abc_2(models.Model):
_name = 'abc.2'
field_b1 = fields.Many2one("abc.1")
field_b2 = fields.Char(string='Sales Person')
I am trying to update records fetched but its not doing anything.
First #api.depends trigger onchange event so you don't need
#api.onchange.
Second don't update the database in onchange event because you will commit
changes to the database what if the user click on cancel button the changes
all ready saved in database.
Third if this code works your querying a lot the database, because any call to write will execute update in database. don't query the database inside a loop only if there is no other solution
Four self.write do not work in #api.onchange because the self is not the record is not the real record it's just a dummy record that holds the data passed from
the client side you can check the id you find is always NewID object even if the record is saved in database. usually you find the real record in self._origin (in new API, or list of ids in old API) in
this you can call write and change the values in database a danger thing to do.
#api.depends('field_a1')
def get_records(self):
# when you use depends, best thing you do is to loop so won't get
# singleton error
for rec in self
# create a list to hold the cammands to create the records
res_ids = []
for res in self.field_a1.member_ids:
# now just add the cammand to the list
res_ids.append((0,0,{
'field_b2':res.name,
})
# if you will affect only one element just
# but if more use rec.update() works like rec.write()
# but with onchange it don't save data in database.
rec.field_a2 = res_ids

How to save one value of Parse object without overwriting entire object?

I have two users accessing the same object. If userA saves without first fetching the object to refresh their version, data that userB has already successfully saved would be overwritten. Is there any way(perhaps cloud code?) to access and update one, and only one, data value of a PFObject?
I was thinking about pushing the save out to the cloud, refreshing the object once it gets there, updating the value in the cloud, and then saving it back. However that's a pain and still not without it's faults.
This seems easy enough, but to me was more difficult than it should have been. Intuitively, you should be able to filter out the fields you don't want in beforeSave. Indeed, this was the advice given in several posts on Parse.com. In my experience though, it would actually treat the filtering as deletions.
My goal was a bit different - I was trying to filter out a few fields and not only save a few fields, but translating to your context, you could try querying the existing matching record, and override the new object. You can't abort via response.failure(), and I don't know what would happen if you immediately save the existing record with the field of interest and null out the request.object property - you could experiment on your own with that:
Parse.Cloud.beforeSave("Foo", function(request, response) {
// check for master key if client is not end user etc (and option you may not need)
if (!request.master) {
var query = new Parse.Query("Foo");
query.get(request.object.id).then(function(existing) {
exiting.set("some_field", request.object.get("some_field"));
request.object = exiting; // haven't tried this, otherwise, set all fields from existing to new
response.success();
}, function(error) {
response.success();
});
}
});

Is it possible to assign new id to jstree nodes copied?

I have two jstree and dnd nodes from one to another using copy_node api. But copied nodes don't have original ids (json data ids). Auto generated ids assign them like 'j2_1'. I have original ids and want to change them with original ids. How can I implement this?
I know, it's been a while since you posted this question. However, I am working right now with jstree and had almost the same "problem".
I used data.original.id to get the original id of my copied item.
And I changed the id using $("#jstree").jstree(true).set_id(data.node,new_id);. In my case, I wanted my new id to involve the original one.
Here is my code block:
// this function is called, if I copy and paste a node
$("#jstree").bind('copy_node.jstree', function (e, data) {
var old_id= data.original.id;
// I just made a new id out of the old one, e.g. appending a number
var new_id = old_id+"1";
$("#jstree").jstree(true).set_id(data.node,new_id);

Entity Framework and Identity Insert

I am writing an application that exports data and serializes it to file for archiving old data.
There may be occasions where for some reason select data needs to be re-imported. This has been causing me a problem because of an identity column.
To get around this I am performing the work inside a transaction scope. Setting the Identity Insert On for that table and then updating my transaction e.g.
using (TR.TransactionScope scope = new TR.TransactionScope(TR.TransactionScopeOption.RequiresNew))
{
// allow transaction nbr to be inserted instead of auto generated
int i = context.ExecuteStoreCommand("SET IDENTITY_INSERT dbo.Transactions ON");
try
{
// check if it already exists before restoring
var matches = context.Transactions.Where(tr => tr.transaction_nbr == t.transaction_nbr);
if (matches.Count() == 0)
{
Transaction original = t;
context.Transactions.AddObject(original);
context.SaveChanges();
restoreCount++;
But I receive an exception saying:
Explicit value must be specified for identity column in table either when IDENTITY_INSERT >is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity >column.
I am assuming the entity framework is trying to do some sort of block insert without specifying the columns. Is there anyway to do this in the entity framework.
The object is large and has a number of associated entities that are also deserialized and need inserting so I want to let the entity framework do this if possible as it will save me a lot of extra work.
Any help is appreciated.
Gert Arnold - that was the answer to my question. Thank you.
I did read that elsewhere and had set the value in the object browser so thought this was suffice. I also double checked the value by right clicking the .edmx and Open With to see the details in an XML editor as suggested in another post.
When I checked the value in the XML editor initially it too was "None" so assumed this wasn't my problem. But I guess just going in there and saving rectified the problem first time around.
The second time round after I must have updated the model from the database I had to repeat this step upon your suggestion. But the second time round the StoreGeneratorPattern was different to the one set in the object browser so I needed to manually change it in the XML.
In my circumstance this is fine since normally the records are inserted via another mechanism so the identity is just getting in the way for me as the identity will always be inserted as an old (used to exist) identity value which is being temporarily restored.
Thanks for your help.

Is it possible to store hidden metadata information that is tied to a specific Table or Cell within a Word document?

I am trying to store metadata (basically a unique id) along with each cell of a table in a Word document. Currently, for the add-in I'm developing, I am querying the database, and building a table inside the Word document using the data that is retrieved.
I want to be able to save any of the user's edits to the document, and persist it back to the database. My initial thought was to store a unique id along with each cell in the table so that I would be able to tell which records to update. I would also like to store some sort of "isChanged" flag within each cell so that I could tell which cells were changed. I found that I could add the needed information into the "ID" property of the cell - however, that information was not retained if the user saved the document, closed it, and re-opened it. I then tried storing the data by adding a data to the "Fields" collection - but that did not work and threw a runtime error. Here is the code that I tried:
object t1 = Word.WdFieldType.wdFieldEmpty;
object val = "myValue: " + counter;
object preserveFormatting = true;
tbl.Cell(i, j).Range.Fields.Add(tbl.Cell(i, j).Range, ref t1, ref val, ref preserveFormatting);
This compiles fine, but throws this runtime error "This command is not available".
So, is this possible at all? Or am I headed in the wrong direction?
Thanks in advance.
Wound up using "ContentControls" to store the information I needed. I used the "Title" field to store the unique id, and the "tag" field to track whether the field had been changed or not. See this link for more info: http://blogs.technet.com/gray_knowlton/archive/2010/01/15/associating-data-with-content-controls.aspx
Since a "Word 2007 Document" is XML, you can add a namespace to the document then adore the elements with attributes from your namespace. Word should ignore your namespace when loading and saving. Moreover, you can add new elments to store any information (metadata) needed.
With that said, I have not used this technique with Word, but I have done it successfully using Excel 2003.
First thing to try, is create a bare "Word 2007 Document". In your case, add a simple two by two table. Open it with a text or XML editor and add your namespace, and adore an attribute and add an element. Open with Word make a change then save it. Open with editor and make sure your namespace attribute and element have not been changed.