Populating a form based on user Identity

1
0
-1

Using Bonita version 7 community edition. Using basic Javascript no added features or add ins.

I have been attempting to have my form appear customized, based on the user ID of who opens the form. The form will display images and information relevant to that user/group.

I started with a simple test of getting an image to populate based on the 'user_name' of the person opening the form. In order to accomplish this I created a local API call which returns a user name (Ex. 'Bill.Smith'). The API call is a variable on the form called 'Identity', so in order to get the username to appear in a text field you would need to type something to the effect of {{Identity.user_name}}.

The image itself will be populated in a custom widget.

In the Template of that custom widget:

  1. <body>
  2. <img src="blank.png" id="image" alt="No Image Found">
  3.  
  4. </body>

In the controller of the custom widget:

  1. function($scope){
  2. var ID = 'Bill.Smith'; /* As long as this is set to 'Bill.Smith' img_one appears in the form. 'Jane.Doe' causes img_two to appear. */
  3.  
  4. if(ID === 'Bill.Smith'){
  5. document.getElementById('image').src = "img_one.gif";
  6. }
  7. else if (ID === 'Jane.Doe'){
  8. document.getElementById('image').src = "img_two.png";
  9. }
  10. }

What I am hoping to accomplish is that 'var ID' will assume the value of the actual user_name. I have tried using the properties in the custom widget. '$scope.properties' however this doesn't appear to work.

Any advice about a strategy to get this working? Has anyone tried this before?

Comments

Submitted by Sean McP on Fri, 07/31/2015 - 06:13

In 6 you would have an invisible field on your page with name ID set to the contents of the process variable ID.

This way JavaScript will be able to interrogate the ID field and set the image.

  1. if(document.getElementById('ID').innerHTML === 'Bill.Smith'){
  2. document.getElementById('image').src = "img_one.gif";
  3. }

I think this will also be the case in 7,

regards Seán

No answers yet.
Notifications