cancel
Showing results for 
Search instead for 
Did you mean: 

@capabilities.DeleteRestriction can't use the Dynamic Expressions, it has no effect

used
Discoverer
0 Kudos
66

Hi,expert!

I use annotations to control the property 'stock' of this entity, when its value is equal to 0 can be deleted, but it does not work, I check the value of not 0 in my table, still can be deleted, could you tell my code is wrong?

it is my code:

entity BooksAnalytics : managed
{
    key ID : Integer
        @title : 'ID';
    title : String
        @title : 'Title';
    stock : Integer
        @title : 'Stock';
    category1 : String
        @title : 'Category1';
    category2 : String
        @title : 'Category2';
    publishedAt : Date
        @title : 'Published At';
    authors : Association to one Authors
        @title : 'Author';
}......
//动态删除操作 动态表达式
annotate BooksAnalytics with @(
    Capabilities.DeleteRestrictions: {
        $Type: 'Capabilities.DeleteRestrictionsType',
        Deletable: 
            {$edmJson: {$If: [{$Eq: [{$Path: 'stock'}, 0]}, true,false]}}
        
    }
);

and there is the xml:

used_0-1739935103173.png

it still can be deleted when it’s not equal 0

used_1-1739935447723.png

 

 

View Entire Topic
used
Discoverer

I found a way to work around this by using CodeList's associated entity in the entity, representing the state, and then defining a Boolean field to use for the comment.

entity BooksAnalytics : managed
{
    key ID : Integer
        @title : 'ID';
    title : String
        @title : 'Title';
    stock : Integer
        @title : 'Stock';
    BookStatus   : Association to BookStatus @readonly  //the new
        @title : 'Stutas';
    category1 : String
        @title : 'Category1';
    category2 : String
        @title : 'Category2';
    publishedAt : Date
        @title : 'Published At';
    authors : Association to one Authors
        @title : 'Author';
}......
entity BookStatus : CodeList 
{
  key code : String enum {
    Available = 'A';
    Discontinued = 'D';
  } default 'A'; //> will be used for foreign keys as well
  insertDeleteRestriction: Boolean; // = NOT createDeleteHidden
}......
//动态删除操作 动态表达式
annotate BooksAnalytics with @(
    Capabilities.DeleteRestrictions: {
        $Type: 'Capabilities.DeleteRestrictionsType',
        Deletable: BookStatus.insertDeleteRestriction
    }
);