GSD-RestApi Action event macro


This is a complete list of parameters that event macro must have in order to be properly executed when action of type "macro" takes place.

Parameter Type Description
&res: HJSON IN-OUT JSON Handle with returned error message, if any error occurs
data: HJSON IN Data section from the request
action: HJSON IN JSON Handle with Action
obj: DBOBJECT IN Currently created/modified/deleted object on which action will be executed
&ok: BOOL OUT False when something went wrong, error info will be added to 'res HJSON'

Example declaration:

1
2
INT ExampleActionEvent( HJSON &res, HJSON data, HJSON action, DBOBJECT obj, BOOL &ok )
RETURN( 1 )

Example usage:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
INT ExampleActionEvent( HJSON &res, HJSON data, HJSON action, DBOBJECT obj, BOOL &ok )
  BOOL ok = TRUE;
  HJSON tmp;
  STRING oid, path, class;
  DBOBJECT parentObj;

  tmp = action.GetMember( "object" );
  IF( tmp == NULL )
    res.xRestApi_Error_Missing_ActionsAssignObject();
    ok = FALSE;
  ELSEIF( tmp.GetType() != JSONT_STRING )
    res.xRestApi_Error_InvalidType_ActionsAssignObject();
    ok = FALSE;
  ELSE
    oid = tmp.GetString();
  ENDIF

  IF( ok )
    tmp = action.GetMember( "path" );
    IF( tmp != NULL )
      IF( tmp.GetType() != JSONT_STRING )
        res.xRestApi_Error_InvalidType_ActionsAssignPath();
        ok = FALSE;
      ELSE
        path = tmp.GetString();
      ENDIF
    ENDIF
  ENDIF

  IF( ok )
    tmp = action.GetMember( "class" );
    IF( tmp != NULL )
      class = tmp.GetString();
    ENDIF
    IF( xRestApi_CheckObjectAccessFromEx( oid, res, parentObj, SR_WRITE, class ) )
      IF( !DBDocAssign( obj, parentObj, path ) )
        res.xRestApi_Error_Error_DocAssign();
        ok = FALSE;
      ENDIF
    ELSE
      ok = FALSE;
    ENDIF
  ENDIF

RETURN( 1 )