Topic
  • 9 replies
  • Latest Post - ‏2013-02-13T15:32:01Z by SystemAdmin
Romy01
Romy01
86 Posts

Pinned topic Binding Data To A Field ( v8.0)

‏2012-06-05T18:42:28Z |
Hi All,

In previous release of IBM BPM , to bind value to a variable from custom HTML , we could simply get the id of the field and assignment was pretty simple. However, I am trying to perform similar task of setting a value to a field that is part of an existing Coach View from a custom script that is in the coach view. Is there a way to perform such assignment apart from using the binding object in the behaviour tab of the coach view ?

Actually I am trying to implement a popup window with values being passed back to the parent window from the popup window. But, I am not sure about the appropriate place to put the callback function in. I tried putting it inside the coach view as a custom script, the callback function is getting invoked but I am not sure about setting the values of the fields that are present in the coach view.

Thanks,
Ramesh
Updated on 2013-02-13T15:32:01Z at 2013-02-13T15:32:01Z by SystemAdmin
  • kolban
    kolban
    3316 Posts

    Re: Binding Data To A Field ( v8.0)

    ‏2012-06-06T14:46:49Z  
    Hi Romy01,
    Great question and I'll be delighted to work with you on this. I am just starting my own study on Coach Views but have been studying hard so I'd like the opportunity to see how far along I am. My understanding is that for a Coach View, there is a single piece of data that can be "bound" to the Human Service variables. So there is a maximum of a 1-1 relationship between a Coach View and a Human Service variable. Note that the Human Service variable can be a Business Object with lots of properties/fields.

    The way to access the binding is with:

    value = this.context.binding.get("value")

    and

    this.context.binding.set("value", newValue)
    (Note that "value" is actually the string "value"

    Neil
  • Romy01
    Romy01
    86 Posts

    Re: Binding Data To A Field ( v8.0)

    ‏2012-06-06T17:16:52Z  
    • kolban
    • ‏2012-06-06T14:46:49Z
    Hi Romy01,
    Great question and I'll be delighted to work with you on this. I am just starting my own study on Coach Views but have been studying hard so I'd like the opportunity to see how far along I am. My understanding is that for a Coach View, there is a single piece of data that can be "bound" to the Human Service variables. So there is a maximum of a 1-1 relationship between a Coach View and a Human Service variable. Note that the Human Service variable can be a Business Object with lots of properties/fields.

    The way to access the binding is with:

    value = this.context.binding.get("value")

    and

    this.context.binding.set("value", newValue)
    (Note that "value" is actually the string "value"

    Neil
    Thanks Neil for your time.

    I did come across the "this.context.binding.get("value")" , but not confident enough to put it to use.
    Here is what I am able to achieve till now,

    1) Have a button on the coach view say myPopup. On click of the button I am invoking window.open(url) where URL is the url representation of the service with input parameters in it. The popup just works fine and it accepts the input parameter as well.

    2) From the popup window , I need to pass few values back . The only way to do that is define a callback function in the parent window and call the function from the popup using "window.opener.callbackFunction('someVar')".

    3) The callbackFunction function is defined in a custom script in my coach view. I am able to invoke the callbackFunction as well.

    4) The next challenge is to bind the values available in the callBackFunction function into the business objects or binidngs on the coach view.

    The step - 4 is where I do not have clear picture of because as you suggested "this.context.binding.set("value", newValue)" probably won't work any because the context object is accessible only in the behaviour tab of the coach view.
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: Binding Data To A Field ( v8.0)

    ‏2013-02-09T09:34:18Z  
    • Romy01
    • ‏2012-06-06T17:16:52Z
    Thanks Neil for your time.

    I did come across the "this.context.binding.get("value")" , but not confident enough to put it to use.
    Here is what I am able to achieve till now,

    1) Have a button on the coach view say myPopup. On click of the button I am invoking window.open(url) where URL is the url representation of the service with input parameters in it. The popup just works fine and it accepts the input parameter as well.

    2) From the popup window , I need to pass few values back . The only way to do that is define a callback function in the parent window and call the function from the popup using "window.opener.callbackFunction('someVar')".

    3) The callbackFunction function is defined in a custom script in my coach view. I am able to invoke the callbackFunction as well.

    4) The next challenge is to bind the values available in the callBackFunction function into the business objects or binidngs on the coach view.

    The step - 4 is where I do not have clear picture of because as you suggested "this.context.binding.set("value", newValue)" probably won't work any because the context object is accessible only in the behaviour tab of the coach view.
    I need to programmatically bind a business object's property to a custom HTML field that I have dynamically created.
    • Here is how I am updating business object's property on a button-click:

    var personObj = this.context.binding.get("value");
    personObj.name = "NEW-NAME-GOES-HERE!!";
    • Here is a coachView's behavior load script ... which sets the binding on PersonObject - but the callback does NOT get called when the button-click modifies person's name.

    var personObj = this.context.binding.get("value");
    personObj.bind("name",function(event){
    //OOPES, This does NOT seem to work! This function NEVER gets invoked for some reason, when I programmatically change the personObject's property value ...
    console.log("binding event received event.type="event.type", event.property="event.property", event.newVal="+event.newVal);
    alert("binding event received event.type="event.type", event.property="event.property", event.newVal="+event.newVal);
    },this);

    Any idea, what am I doing wrong?
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: Binding Data To A Field ( v8.0)

    ‏2013-02-09T09:38:30Z  
    I need to programmatically bind a business object's property to a custom HTML field that I have dynamically created.
    • Here is how I am updating business object's property on a button-click:

    var personObj = this.context.binding.get("value");
    personObj.name = "NEW-NAME-GOES-HERE!!";
    • Here is a coachView's behavior load script ... which sets the binding on PersonObject - but the callback does NOT get called when the button-click modifies person's name.

    var personObj = this.context.binding.get("value");
    personObj.bind("name",function(event){
    //OOPES, This does NOT seem to work! This function NEVER gets invoked for some reason, when I programmatically change the personObject's property value ...
    console.log("binding event received event.type="event.type", event.property="event.property", event.newVal="+event.newVal);
    alert("binding event received event.type="event.type", event.property="event.property", event.newVal="+event.newVal);
    },this);

    Any idea, what am I doing wrong?
    Forgot to mention, I'm using BPM standard v8.0.1 - process designer.
  • kolban
    kolban
    3316 Posts

    Re: Binding Data To A Field ( v8.0)

    ‏2013-02-09T23:30:17Z  
    Forgot to mention, I'm using BPM standard v8.0.1 - process designer.
    Hi there,
    Looks like your code got eaten by the forum. To include code, surround it by

    Open Curly Brace "code" Close Curly Brace

    ... code goes here ...

    Open Curly Brace "code" Close Curly Brace

    Neil
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: Binding Data To A Field ( v8.0)

    ‏2013-02-11T07:53:52Z  
    • kolban
    • ‏2013-02-09T23:30:17Z
    Hi there,
    Looks like your code got eaten by the forum. To include code, surround it by

    Open Curly Brace "code" Close Curly Brace

    ... code goes here ...

    Open Curly Brace "code" Close Curly Brace

    Neil
    Here is attempt#2 :)

    I need to programmatically bind a business object's property to a DOJO widget that I have dynamically created on the fly (my coach is plain old Custom HTML). Here is how I am updating business object's property on a button-click, just to trigger the change, and I am expecting to get called-back in a function which will in turn update the dynamically generated dojo widget:

    
    var personObj = this.context.binding.get(
    "value"); personObj.name = 
    "NEW-NAME-GOES-HERE!!";
    


    Here is a coachView's behavior load script ... which sets the binding on PersonObject - but the callback does NOT get called when the button-click modifies person's name.

    
    var personObj = this.context.binding.get(
    "value"); personObj.bind(
    "name",function(event)
    { 
    //OOPS, This function NEVER gets invoked for some reason! console.log(
    "binding event received event.type="event.type
    ", event.property="event.property
    ",   event.newVal="+event.newVal); alert(
    "binding event received event.type="event.type
    ", event.property="event.property
    ", event.newVal="+event.newVal); 
    },
    
    this);
    


    Any idea, what am I doing wrong?
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: Binding Data To A Field ( v8.0)

    ‏2013-02-12T15:50:53Z  
    Here is attempt#2 :)

    I need to programmatically bind a business object's property to a DOJO widget that I have dynamically created on the fly (my coach is plain old Custom HTML). Here is how I am updating business object's property on a button-click, just to trigger the change, and I am expecting to get called-back in a function which will in turn update the dynamically generated dojo widget:

    <pre class="jive-pre"> var personObj = this.context.binding.get( "value"); personObj.name = "NEW-NAME-GOES-HERE!!"; </pre>

    Here is a coachView's behavior load script ... which sets the binding on PersonObject - but the callback does NOT get called when the button-click modifies person's name.

    <pre class="jive-pre"> var personObj = this.context.binding.get( "value"); personObj.bind( "name",function(event) { //OOPS, This function NEVER gets invoked for some reason! console.log( "binding event received event.type="event.type ", event.property="event.property ", event.newVal="+event.newVal); alert( "binding event received event.type="event.type ", event.property="event.property ", event.newVal="+event.newVal); }, this); </pre>

    Any idea, what am I doing wrong?
    Hi,

    Try

    
    var personObj = this.context.binding.get(
    "value"); personObj.set(
    "value", 
    "NEW-NAME-GOES-HERE!!");
    


    instead of

    
    var personObj = this.context.binding.get(
    "value"); personObj.name = 
    "NEW-NAME-GOES-HERE!!";
    


    I hope it helps,

    VF
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: Binding Data To A Field ( v8.0)

    ‏2013-02-13T12:13:43Z  
    Hi,

    Try

    <pre class="jive-pre"> var personObj = this.context.binding.get( "value"); personObj.set( "value", "NEW-NAME-GOES-HERE!!"); </pre>

    instead of

    <pre class="jive-pre"> var personObj = this.context.binding.get( "value"); personObj.name = "NEW-NAME-GOES-HERE!!"; </pre>

    I hope it helps,

    VF
    Thanks VenFil for your comments. It helped me get past the issue. I would only like to clarify one thing. In the API we mention the string "value" which I believe maps to the binding object (in scenarios where we have a complex object being bound). Hence if I want to trigger a custom callback which I want to get executed on change of one of the property of the complex object then I should be mentioning the propertyName instead of the "value" in the set API. Illustrated by code snippet below.

    
    
    //Assuming I have a person complex object which has properties like name, address etc. On change of the address property I want to  
    //trigger a custom callback 
    //Get the binding complex object using the get API. var personObj = this.context.binding.get(
    "value"); 
    //Bind the "address" property of the complex object with a custom callback personObj.bind(
    "address",function(event)
    {alert(
    "Custom callback triggered!!!!"
    };)); 
    //The below code on click of the button modifies the "address" property of the complex object var button = this.context.getSubview(
    "changeAddress")[0]; button.context.element.onclick=dojo.hitch(this, function()
    { var newAddress = 
    "New address."; 
    //This SET API will invoke the custom callback function personObj.set(
    "address", newAddress); 
    });
    


    Thanks,

    Nilesh
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: Binding Data To A Field ( v8.0)

    ‏2013-02-13T15:32:01Z  
    Thanks VenFil for your comments. It helped me get past the issue. I would only like to clarify one thing. In the API we mention the string "value" which I believe maps to the binding object (in scenarios where we have a complex object being bound). Hence if I want to trigger a custom callback which I want to get executed on change of one of the property of the complex object then I should be mentioning the propertyName instead of the "value" in the set API. Illustrated by code snippet below.

    <pre class="jive-pre"> //Assuming I have a person complex object which has properties like name, address etc. On change of the address property I want to //trigger a custom callback //Get the binding complex object using the get API. var personObj = this.context.binding.get( "value"); //Bind the "address" property of the complex object with a custom callback personObj.bind( "address",function(event) {alert( "Custom callback triggered!!!!" };)); //The below code on click of the button modifies the "address" property of the complex object var button = this.context.getSubview( "changeAddress")[0]; button.context.element.onclick=dojo.hitch(this, function() { var newAddress = "New address."; //This SET API will invoke the custom callback function personObj.set( "address", newAddress); }); </pre>

    Thanks,

    Nilesh
    Thanks Nilesh, VF,

    Interesting, so basically :

    Instead of
    
    personObj.propertyName = 
    "propertyValue";
    


    if you change the property using the "set" function, i.e.,

    
    personObj.set(
    "propertyName",
    "propertyValue");
    


    Then the callback configured using the bind API does get triggered.