Handling general beforeProcessDeltaChange

In your tutorial, the chapter on “Adding Tasks” has the following example.

function beforeProcessDeltaChange(delta, change, wasRefreshed, canRemove)
{
if (delta.name == “Tasks” && change.isInsert) {
var userId = session[‘Login.Id’];
change.newValues[‘User’] = userId;
canRemove = false;
}
}

This gives me the idea of centralising all handling of userid in different tables like this:

function beforeProcessDeltaChange(delta, change, wasRefreshed, canRemove)
{
if (delta.//has a field by name User// && change.isInsert) {
var userId = session[‘Login.Id’];
change.newValues[‘User’] = userId;
canRemove = false;
}
}

Is there a way to implement the “//has a field by name User//” part? I have searched the wiki for information on this, but can’t see any.

Why do I have to set canRemove to False? This is not a delete…

/Anders

Hello

We will consider to make the needed API changes for the next Beta (it should be ready early next week). In that case script would look like

 if ((change.table.getField('Name1') == null) && change.isInsert)
...

Name1 here is a field that doesn’t exist.

This flag is used to tell the server that this DeltaChange should not be removed from a list of delta changes that will be sent back to the clients. In most cases when a Delta is sent from the client to the server the last applies it and doesn’t sent anything back to the client. But in the case when some field values are calculated on the server side (f.e. auto increment values or fields calculated via script) server needs to send the calculated values back to the client so it will be able to merge these values into the data stored on the client side.

Regards

1 Like

Thanks, nice! Looking forward to that. Thanks also for the nice explanation on the flag :smile:

/Anders