Client API can be used directly in BellaDati reports to display various information. These examples are showing how to display username and first name with last name of currently signed user. User API is used in this examples.

Display Username in Custom Content

  1. Open any report and switch to edit mode.
  2. Add new custom content to the report.
  3. Save the empty custom content, open developer tools in your browser and copy the ID of the textViewZone:
     
  4. Edit the custom content and switch to source mode.
  5. Past this code to the text area. Don't forget to change the URL from http://localhost:8080 to your own server and the ID of the textViewZone.

    <script>
    $.ajax({
      url: "http://localhost:8080/user/api:signedUser",
      success: function(reply) { 
         $('#textViewZone_44-NtmSWuOWIf div').append('<h3>Username of currently logged-in user is '+reply.username+'.</h3>');
       },
       xhrFields: {
          withCredentials: true
      }
    });
    </script> 
  6. Save the custom content.
  7. The result should look like this:

Display First and Last Name in Custom Content

To be able to display the first and last, we need to create to API calls. The first one is returning the ID of currently logged-in user (the same code as in first example) and the second one is returning detailed information about specific user ID.

  1. Open any report and switch to edit mode.
  2. Add new custom content to the report.
  3. Save the empty custom content, open developer tools in your browser and copy the ID of the textViewZone:
     
  4. Edit the custom content and switch to source mode.
  5. Past this code to the text area. Don't forget to change the URL from http://localhost:8080 to your own server and the ID of the textViewZone.

    <script>
    $.ajax({
      url: "http://localhost:8080/user/api:signedUser",
      success: function(reply) { 
       $.ajax({
          url: "http://localhost:8080/user/api:detail/" + reply.id,
          success: function(reply2) {
             $('#textViewZone_44-s3J8qIBxTp div').append('<h3>First and last name of currently logged-in user is '+reply2.firstName+' '+reply2.lastName+'.</h3>');
               }});
              },
        xhrFields: {
        withCredentials: true
      }
    });
    </script> 
  6. Save the custom content.
  7. The result should look like this:

You can download BellaApp with both example from here.

 

 

  • No labels