Triggers in Outsystem

Triggers in Outsystem

  

Hi,

I want to achieve trigger concept in Outsystem. In my application, totally two entities are there. When i insert value in first entity then some value has to be updated in second entity. Please help me.

Hi Dyvia,


You can encapsulate both creating the record in first entity and updating value in the second in the single action. Pay attention that in this scenario, by default, both actions would be part of a single transaction meaning that if updating the second entity fails, the creating record in the first one is rollbacked.


If you are seeking for the updating of the second record to be something assynchronous and to run in the background, you can use a BPT:


Note that in this scenario, the trigger is on the database and that you would have to check the "Expose process events" option in the table where the trigger is.


Hope it helped.

Hi Divya,

You cannot create any trigger from outsystems directly from service center .The other way is you can create a trigger in the database and it will do the work for you .


Regards

-PJ-

João Marques wrote:

Hi Dyvia,


You can encapsulate both creating the record in first entity and updating value in the second in the single action. Pay attention that in this scenario, by default, both actions would be part of a single transaction meaning that if updating the second entity fails, the creating record in the first one is rollbacked.


If you are seeking for the updating of the second record to be something assynchronous and to run in the background, you can use a BPT:


Note that in this scenario, the trigger is on the database and that you would have to check the "Expose process events" option in the table where the trigger is.


Hope it helped.

Hi João,

      Thanks for your reply. I am new to Outsystem. I am not aware of Process concept in Outsystem. What does process do?


Hi Divya,

Process are used for a very specific purpose , you need to first understand the concept why we do need process and whether it fits in your case or not.

If it just about one trigger you can implement it from db side as i advised you earlier .

See this link to understand what a process is and what  are different things you can achieve using process.

I hope this will help you in understanding the concept.

Regards

-PJ-

PRAMOD JAIN wrote:

Hi Divya,

Process are used for a very specific purpose , you need to first understand the concept why we do need process and whether it fits in your case or not.

If it just about one trigger you can implement it from db side as i advised you earlier .

See this link to understand what a process is and what  are different things you can achieve using process.

I hope this will help you in understanding the concept.

Regards

-PJ-


Hi Pramod,

     Can i use SQL to create trigger in Outsystem? 

Hi Divya,

Advance Sql is not to be used like that. What I recommend for your use case is to do what João suggested. Create a new action called PersonalUpdate<Entity1Name> and you will start to use always this one action instead the entity1  action to update. On this action beside updating the entity1 you will also update entity2.

Regards,

Marcelo

I agree, the best way to create triggers seems to be BPT. Easy to read the code and helpful for maintenance.

Hello divya v

I have a question for you.

Is YOUR app that will insert a value in the entity, or is some OTHER app that will insert value in the entity?

In the first case, you can simply write your logic, so that when you insert a value in one entity you insert the value in the other.

If it is the second case, so your application needs to answer to another app inserting records in the entity, externally, you can follow the BPT process approach (you will have to study it), https://www.outsystems.com/learn/courses/17/master-class-on-modeling-business-processes-bpt/?StartCourse=False

Or you can have a timer that from time to time check the entity to see if there are new records and simply process those records (creating records in another entity, etc).

Or, but I am usually against it, you can go directly into the database (if you have access to it) and write a Stored Procedure and a trigger. But remember that it wull not be deployed together your app to a production server, so you will have to keep track of it, etc.

Cheers.

divya v wrote:

Hi,

I want to achieve trigger concept in Outsystem. In my application, totally two entities are there. When i insert value in first entity then some value has to be updated in second entity. Please help me.

What you'll have to do is to create a new Server Action (Logic Tab), that you'll be using instead of the standard one. 

In example: 

You have 3 entities: Person; Department and GlobalStatsDepartment 

The goal is, everytime a Person is created, we want to update that Department stats table (GlobalStatsDepartment).

So, in some screen, you'll have a screen action responsible to do this. When you scaffold in outsystems, by default it'll be named Save. And looks like this:

The solution is to use a custom create action, to use instead of the CreateOrUpdatePerson action you see above. You create a new server action, that looks something like this:

PersonREC input is the new record, The outputs: ErrorMessage is error text in case of insuccess; Success is a boolean; and PersonId is the ID of the new Person created (its an ouput of the standard CreatePerson action).

Now you're able to use the new action in your screen and get the desired behaviour (create references if needed).

To show the error, in case there's one (like not finding the GlobalSatsDepartment for that DeparmentId), I'll evaluate the Success output of the created action, and Feedback_Message the ErrorMessage output, in case Success = False.


Hope this helped :) Good luck in your Outsystems journey!


José Lopes wrote:

divya v wrote:

Hi,

I want to achieve trigger concept in Outsystem. In my application, totally two entities are there. When i insert value in first entity then some value has to be updated in second entity. Please help me.

What you'll have to do is to create a new Server Action (Logic Tab), that you'll be using instead of the standard one. 

In example: 

You have 3 entities: Person; Department and GlobalStatsDepartment 

The goal is, everytime a Person is created, we want to update that Department stats table (GlobalStatsDepartment).

So, in some screen, you'll have a screen action responsible to do this. When you scaffold in outsystems, by default it'll be named Save. And looks like this:

The solution is to use a custom create action, to use instead of the CreateOrUpdatePerson action you see above. You create a new server action, that looks something like this:

PersonREC input is the new record, The outputs: ErrorMessage is error text in case of insuccess; Success is a boolean; and PersonId is the ID of the new Person created (its an ouput of the standard CreatePerson action).

Now you're able to use the new action in your screen and get the desired behaviour (create references if needed).

To show the error, in case there's one (like not finding the GlobalSatsDepartment for that DeparmentId), I'll evaluate the Success output of the created action, and Feedback_Message the ErrorMessage output, in case Success = False.


Hope this helped :) Good luck in your Outsystems journey!


Hi José,

       Why do we use custom create action instead of the CreateOrUpdatePerson action? and also what does below save screen action do?. since you have done all logic in Create_person screen action.


Hi divya v,

Hi José,

       Why do we use custom create action instead of the CreateOrUpdatePerson action?

You use your custom Create_Person server action so you can control what happens when you create a new record of the Person entity (in this example it's to guarantee you also update the corresponding GlobalStatsDepartment entity record, but could be to add business validations, for instance).

This is actually a common pattern for OutSystems service-oriented architectures.

and also what does below save screen action do?. since you have done all logic in Create_person screen action.

The Screen Action is called from the Save button on the screen, and will create the Person record (and along with it update the corresponding the GlobalStatsDepartment record).

In this case, it's first guaranteeing the built-in validations all passed, in order to safely call your business logic. After calling the Create_Person, and based on the outcome of that operation, it will show the appropriate feedback message.

The main difference between this version and the original scaffolded one is that it replaced the Entity Action CreateOrUpdatePerson for the custom Create_Person Server Action, but since that server action is not relying on Exceptions to signal an error, it needs to check the success return value in order to decide what feedback message to show the user.

Hope this further clarifies João's, Eduardo's and José's answers...

Hi All,


The best option for this is definitely a trigger on entity at DB level.


Thanks!

JitendraYadav wrote:

Hi All,


The best option for this is definitely a trigger on entity at DB level.


Thanks!

I can't agree that the option you purpose is the best. At least for the most cases

That solution is invisible in the Outsystems platform and it may get harder to maintain.


José Lopes wrote:

JitendraYadav wrote:

Hi All,


The best option for this is definitely a trigger on entity at DB level.


Thanks!

I can't agree that the option you purpose is the best. At least fot the most cases

That solution is invisible in the Outsystems platform and it may get harder to maintain.


Agree, keep the trigger inside create or update action or on a BPT process is easier to mantain