Ticket Entity Changed vs Entity Updated

Hello,

Note: What I would like:

  • when customer assigned to ticket (does not matter if table also assigned) => CPT = 1
  • when no customer assigned to ticket => CPT = 0

I don’t see the difference between these 2 events:

  • Entity Update
  • Ticket Entity Changed

Rules:

  • Rule1: that is supposed to put 0 into a ticket tag (CPT) when Ticket Entity Changed, no constraint, always fired.

  • Rule 2: that set 1 to CPT ticket tag when Ticket Entity Changed under constraint (Entity = Customer), that’s working.

  • When adding a customer (Select Customer) to the ticket, CPT = 1, OK.
  • When Deleting the customer (Select Customer, press delete), so no more Customer Entity assigned to the ticket, so, first rule still fired (CPT=0) and the second rules should not be fired, however CPT is still = 1.

Any clue?

Do i have to use Entity Updated instead?

Rule1: Adding contraint 1 = 1 (always)
Rule2: Match all

Click on Select Customer and go back (i.e select none) will fired rule 2 and set CPT to 1.

Behaviour of these 2 events are really confusing.

Somebody knows exactly when is fired:

  • Entity Update
  • Ticket Entity Changed

Ticket Entity Changed is just what it says - you add, remove, or change an entity assigned to a ticket.

Entity Updated is after the entity’s custom data has changed.

In your scenario, I would use the Ticket Entity Changed event with two actions. One action with a constraint if there’s a specific entity type assigned to the ticket, and one with a constraint when there isn’t a certain entity type assigned to the ticket (setting tag value 0/1)

This is what I thought, but no.

Ticket Entity Changed is fired when click on the button Select Customer.

It does not matter if Entity has not changed, if no entity was chosen. As soon as you click Select Customer, rule is fired with that event.

So the constraints will not behave as expected neither because Entity [Type] Name will be evaluated before an entity is chosen.

Example:

  • I click on Select Customer, the customer entity search screen shows up.
  • I click on the left arrow :left_arrow: to go back to the ticket without choosing a customer.
  • CPT ticket tag = 1 (rule fired by the event Ticket Entity Changed, even tough: Entity has not changed (it was NULL, it is still NULL).
    Also constraints were useless:
    Constraint Entity Name is not null and in my example Entity Name is null (before and after the rule).

App 5.7.20
DB 217

2025-08-26_19;26_1756258019_Samba.Presentation

db:
DefaultInstall_202508261928SQM.zip (584.2 KB)

1 Like

ok memo, understood, easier.

thanks

Ok I did it that way, it work well for CPT = 0 or 1.

I added a third action to that Ticket Entity Changed rule (memo).

That action execute a script that use an API to get the extra data about that Entity (actually Entity = Empresa).

It works however with “some delay”:

I enter the number of that company and if new company, the script look for address, name, … and update the CustomData(json) of SambaPOS5.dbo.Entities table with this extra data.
When I select the new company, the ticket screen is shown again.

but on the top of the Ticket, I only see the number of the company, not the name.

If I Change Empresa again and go back, now the ticket shows the updated data: Number + Company Name.

entityChanged

I was wondering if there was a solution, so that when coming back to the ticket screen, I could see the name of the company immediately, without entering in Change Empresa and back.

I try putting that action with Entity Updated but without success

We need to see what’s going on in the script you’re calling and what data you’re reading and trying to set. Yeeting to the JS engine with a SQL query and JSON manipulation can introduce some latency.

Yeeting to the JS engine with a SQL query and JSON manipulation can introduce some latency

I don’t think it’s latency, it’s more of when to execute that script and when exactly is triggered Ticket Entity Changed.

I try with Entity Updated which I thought was triggered when (New Empresa/Modify Empresa) Save is pressed, but no luck.

Details:

Entity Type: Empresas

Rule/Action/script

function GetCompanyInfo(ruc)
{
    var token = "xxx.YYY";
    var url   = "http://api.decolecta.com/v1/sunat/ruc?numero=" + ruc + "&token=" + token;

    // POST vacío (sin body)
    var response_json = web.PostData(url, "");

var razon = "";
var direccion = "";

if (response_json.indexOf('"razon_social"') == -1) {
    // no razon_social key in the response → treat as invalid RUC
    razon     = "ERROR RUC";
    direccion = "";
} else {
    var data = JSON.parse(response_json);
    razon     = ("" + data.razon_social).replace(/"/g,'""');
    direccion = data.direccion ? ("" + data.direccion).replace(/"/g,'""') : "";
}

    var customData = '[{"Name":"Address","Value":"' + direccion + '"},'
                   + '{"Name":"Name","Value":"'    + razon     + '"},'
                   + '{"Name":"IdCode","Value":"6"}]';

    var sqlUpdate = "UPDATE SambaPOS5.dbo.Entities "
                  + "SET CustomData = '" + customData + "' "
                  + "WHERE Name = '" + ruc + "'";
                  
    sql.ExecSql(sqlUpdate);

    return "Entity " + entityId + " updated.";
}

With the HTTP call there’s going to be a delay.

Another option you have is to mark the action async and that should not block on the UI thread like it normally would.