Saturday, May 30, 2015

How to use server side variable in custom html script of IBM BPM Coach

In this post, let us look at how display the value from a server side variable on a coach using custom html.

In older versions of IBM BPM i.e., before v8.0 it is easier to both bind a server side variable and access value of server side to a custom html using the syntax tw#local#variable using which a variable can be bound to any input control of the custom html which enables us to get or set the value to or from the variable.
But starting from the v8.0 after the introduction of new coaches and coach view, the above syntax no longer works and it is also not possible to set the value to a server side variable directly from the input control but it is possible to get the value using the below syntax.

Directly in coach :
{{tw.local.variable}}    

In Coach view :
 To Access business Data variable:
     {{tw.businessData.variable}}

 To Access configuration variable:
     {{tw.options.variable}}


Below illustration shows a sample code on how to use server side variable in custom html.

Below image shows a private variable with a default value.


Below image shows the script in the custom html which uses the above variable.


After performing the above two steps in a Human Service. Run the human service to launch the coach and you will see the below screen.

The disadvantage of this approach in using server side variable in the custom html of the coach is that, it is not possible to set the value of a server side variable. 

If any one found a way on how to set a value to the server side variable from custom html, please post a comment below. I can add the same here. Thanks. 

Thanks for stopping by. If you like this post leave a comment, share it and do a g +1.



8 comments:

  1. i've tried to mimic your example above in 8.5.5, but when the custom html displays, instead of showing the contents of the variable it displays the script as a string. for example {{tw.local.myvar}} displays {{tw.local.myvar}} bolded. I tried selecting the variable radio button rather than text, and binding to myvar. this works in showing the initial value of myvar, but if i change the value of myvar in a server-side scrfipt, the custom-html cv doesn't refresh. any suggestions?

    ReplyDelete
    Replies
    1. The custom html will never refresh that variable. Once it is rendered, it stays like that. If you want it to be refreshed, unfortunately, you would have to use an output text control.

      Delete
    2. I am creating html table with this approach but it doesnot refresh the data... if I use output text then it will show the plain text insteade of creating HTML object. Is there any other solution?

      Delete
  2. Hi, This is the limitation with this approach. It will not refresh the value of the variable incase if it is changed.

    ReplyDelete
  3. Thanks for detailed explanation! Unfortunately, many program codes are not well-secured and besides have some internal issues. That is why as I read despite online data room protection like Ideals data room some companies lose their data.

    ReplyDelete
  4. Hi, In similar way can we fetch the environment variables like {{tw.env.somename}} in coach views

    ReplyDelete
  5. It seems we are not able to access the env variable in this fashion also we are not able to access local variables from an external js file... guys any thoughts on this????

    ReplyDelete
  6. Hi Thanks for such a good article but I need to get values of some system class directly in custom html inside CV without taking configuration variable. Is there any way to do it?

    ReplyDelete