Generic Action to Enable/Disable Entity Records using IsActive field

Generic Action to Enable/Disable Entity Records using IsActive field

Hi everybody

I am dealing with the following scenario: every Entity in my model have to have an IsActive field. In details page i can change the state without problem. What i want is to have an action in every list page to change that state to avoid the need to go to detail page to change that specific field. Can i have a "generic" action to do this? As far as I have read documentation, i would end up duplicating this behaviour in every entity-list page.

Thanks for any help
Hi Johannes,

You can create a User Action which receives as an input the identifier for your entity and updates the record. You can then use that action in your Screen Actions without having to duplicate your code.

Hope this helps,
Hi Guiherme. That was the first approach I tried. the problem is: The input parameter has to be an Identifier of an specific type, lets say, Order Identifier. What I would like is to be able to pass as parameters the value of the identifier and the name or the type of the Entity, instantiate the identifier and the update the entity. Something like this:

Identifier id = new Identifier(InputValue)
Entity b = GetEntity(id, "entityname")
if(b.hasIsActiveAttribute, b.isActive=false)

Is there any API that allows me to do something like that? Should I think in writing an Extension to accomplish this?
Hi Johannes,

I don't think there's a specific API for that. If that really is a requirement what you could do is in your action you receive all that and then you can use the SQL widget with an unescaped input variable.

You'd need to generate the customSql expression to pass onto the widget but if your tables have a similar structure it should be easy.

Something like this (just an example not really working):

Hi Guiherme. Good Idea. I will try and let you know.
Hi Guiherme. I tried the approach you suggested. I am having a problem when the SQL is executed. 

The first time I constructed the complete UPDATE statement, whit values, and the result was:

Then I am trying building a CustomSQL this way, UPDATE {CountryState} SET {CountryState}.[IsActive] = @State where {CountryState}.[Id] = @Id, using parameters. When I test it on Service Studio I get this error:

Would you have any idea? 
I am thinking that what i want is not currently possible due the strongly typed mechanisms of the platform. Is not really and issue or a requirement, maybe it is an scenary that could be suggested as an improvement idea.

I think am not going to spend more time and i will follow a more traditional approach although it implies lot of duplication.

I also suggest for you to use "more standard" mechanisms as they are easier to maintain.

Howhever looking at your previous post I believe you should contruct with values (like in your initial approach) but make sure your "CustomSQL" param inside the SQL Widget is set as expand inline 

Guiherme, you are a genius ;) The expand inline attribute did the work. Thanks a lot!!! Now I have to get feedback of the operation to send an appropiate message to user, but now thats another question!!! Thanks a lot!!!