BPM, Workflow, and Case

 View Only
  • 1.  Coach Programming 101 Information

    IBM Champion
    Posted Mon April 15, 2024 07:35 PM

    I am trying to get a couple of new developers up to speed in BAW Coach programming, all the tw objects and syntax and such.  So many articles are years old and even then I find find the initial, basic stuff.  Like I want to add a little JS code in a coach UI, who to reference the TW object.  They are getting errors of ts does not exist sort of errors.  Appreciate in advance any information this group might have.

    Thank you.



    ------------------------------
    Mike Prentice
    ------------------------------


  • 2.  RE: Coach Programming 101 Information

    Posted Tue April 16, 2024 02:21 AM

    You can't access tw.object in Coach View. What you can do to assign the value of tw.object. whatever  to a private variable and you write that code  in Pre or Post Execution Script of Service Flow inside Client Side Human Service then you can use this variable in your CV.



    ------------------------------
    Ahmed Ibrahim
    ------------------------------



  • 3.  RE: Coach Programming 101 Information

    IBM Champion
    Posted Tue April 16, 2024 02:53 PM

    1 - Thanks, I can give that a try.

    2 - I think we still need the original help as I would hate to ask a bunch of one-offs here vs us knowing more.



    ------------------------------
    Mike PrenticeMike Prentice
    ------------------------------



  • 4.  RE: Coach Programming 101 Information

    Posted Tue April 16, 2024 03:23 PM
    I recommend you read this book for building UI https://www.redbooks.ibm.com/Redbooks.nsf/RedpieceAbstracts/sg248355.html . it has been published in 2016 but it has still a useful content. 
     
    IBM Expert Labs do tailored training so maybe this is another option to speed up your team learning journey. 


    ------------------------------
    Ahmed Ibrahim
    ------------------------------



  • 5.  RE: Coach Programming 101 Information

    Posted Wed April 17, 2024 03:38 AM

    Don't do that, if the coach is used as a task in a process, the state is kept and the variable is unreachable upon opening it a second time.

    If you want to access a variable from the tw.local scope, either map it into the custom View through binding, or through configurations if you need multiple. 

    If you just need to access a tw.local variable in the coach itself, bind it to a Data component, and reach it through {myControlId}.getData() from events, or page.ui.get("myControlId") from javascript placed in customHtml components. 

    If you map the data into your own Views through binding, you can reach that value in the loadevent of the view with:

    If you map through binding, you get the value with:
    value = this.context.binding.get("value");

    If you map it through configuration options, you reach them through:
    var tmp = bpmext.ui.getOption(this, "myVar", "");

    If you need to find a component in a coach from within a custom view, you can do something like this:

    function getView(controlId){
    	var orgControlId = controlId;
    	var list = controlId.split(':');
    	var view= page.ui.get(list[0]);
    
    	for(var i = 1; i < list.length; i++){
    		var index = null;
    		var controlId = list[i];
    		var tempview = view.ui.get(controlId);
    		//Handling for lists of repeating rows in tables or repeating layouts
    		if(tempview == null){
    			if ( list[i].indexOf("[") > 0 ) {
    				var leftHookIndex = list[i].indexOf("[");
    				index = list[i].substring(leftHookIndex+1, list[i].length-1);
    				controlId = list[i].substring(0, leftHookIndex);
    			} 
    			tempview = view.ui.getChild(controlId, index); //if index is null only get the view through controlId, just as get()
    		}
    
    		if ( tempview == null || tempview == undefined) {
    			view = null;
    			console.log("Could not get view for controlId: " + orgControlId);
    		} else {
    			view = tempview;
    		}
    	}
    	return view;
    }


    ------------------------------
    Johan Andersson
    ------------------------------



  • 6.  RE: Coach Programming 101 Information

    IBM Champion
    Posted Wed April 17, 2024 12:19 PM

    Thank you Johan.  The Redbook mentioned, yes, I have been using that.  It does seem what I am looking for does not really exist, without paying someone to offer it.  I assumed that might be an option, but as a last resort.

    For example, how/where do you know that tw.object can't be accessed in a Coach View?  The documentation, unless on some obscure page, does not state that, in fact it states tw is accessible everywhere.

    I know I am complicating this some by wanting to create a toolkit as we have a common feature we wanted to build once for a couple of projects, so I need to pass into it a couple of key variables.  Thus, understanding what exists, when it exists, and all that.  The Redbook and some other articles are not bad at explaining state, but there is still an element of basic knowledge that is missing and not explained anywhere.  It seems you either know the product because you knew Lomadri way back or do not.



    ------------------------------
    Mike Prentice
    ------------------------------



  • 7.  RE: Coach Programming 101 Information

    Posted Fri April 19, 2024 02:08 AM

    Damn, you seem to be correct, documentation of the variable scope while using cshs is quite limited. When using CSHS:es, only outside of the coach block can use the tw.local scope. This is a safety feature though, to prevent users from accessing variables unless you have explicitly stated they should be accessible.  Only blocks that can be bound to data can be accessed. 

    I've used the product since 2016, so since IBM BPM 8.5.5 i've been coding in it.

    Regarding adding functions that are reusable inside coaches, the simplest way i've found of doing this is:

    Create a custom View, and add the function within its load event. For example if you want to create a function to add the value from two components, here i have a function with a delayed fire of 2.7 seconds. ControlId is entered, and a function similar to the earlier i linked is used

    The logic for the c

    this.myFunc = function (input, input2) {
    var _this = this;
    setTimeout(function(){
    _this.internalMyFunction(input, input2);
    }, 2700);
    }

    Then add the view to your coach, and to call it use ${MyControlId}.myFunc();

    However, what we mostly end up doing to get reusable functions, is create snippets, add them to a shareable site such as GIT or Confluence, and copy paste the functions to CustomHTML-scripts in the coaches instead. Since most projects will need to make minor adjustments anyway



    ------------------------------
    Johan Andersson
    ------------------------------