Linking a JS object to ScriptUI listbox item

I am writing a script that that takes elements from a document and for each element makes a custom object with its own properties and methods. This list of elements is then spat out into a ScriptsUI listbox.
How do I link each listbox item to its associated obejct? i.e. So if I double click on a listbox item it will run a particular method within that object.
P.S. I dont want to have to store array ids in a column or something hacky like that.

Yep, it seems that the Translator component of the MVVM pattern wouldn't be very useful in a ScriptUI perspective.
The most asbtract pattern you have to deal with, I think, is the GenericList widget (ListBox, DropDownList, maybe TreeView?) and its relationship with what we may call a DataProvider (following Flex and .NET terminology). But ScriptUI/ExtendScript does not allow a serious level of data binding.
The whole problem is to emulate something of a dynamic link so that the data provider can notify the List widget of some changing. As a response, the List then would update its items accordingly. A skeleton of this approach could be drawn using custom event notification:
const EXTERNAL_EVENT_TYPE = 'myEventType';
var externalProcess = function F()
    if( F.targetWidget )
        F.targetWidget.dispatchEvent(new UIEvent(EXTERNAL_EVENT_TYPE));
// =====================================
// UI
// =====================================
var w = new Window('dialog', "Example"),
    // register the LB as a target:
    lb = externalProcess.targetWidget = w.add('listbox'),
    b = w.add('button',undefined,"Test Change");
lb.addEventListener(
    EXTERNAL_EVENT_TYPE,
    function(){ alert("Something is happening. I need to update my items!"); }
b.onClick = externalProcess;
w.show();
but I'm afraid this code—which, by the way, works!—leads us to an anti-pattern! Indeed, while we have to register and maintain a reference to the List widget in the external object (which is assumed to wrap the data), we still need to tell the list how to access the data provider in order to update the list items. The only benefit of the scheme above is that the external process can notify the list at any moment. Maybe this could make some sense in a non-modal context (palette), but this doesn't solve the original problem.
So, intuitively, I would tend to take the opposite view: instead of making the external process trigger some event in the UI when its data change, let simply provide a generic resync() method to the list widget. The paradigm, here, is that a data provider should always be an array structure whose elements expose a toString() or whatever feature. If the list widget has a reference to some data provider, then it can load and/or resync the list items using always the same abstract routines. Then we have something purely prototypal:
ListBox.prototype.load = DropDownList.prototype.load = function(/*obj[]&*/dp)
// =====================================
// A simple load method based on the assumption that
// all dp items offer a toString() ability
    // Manage a reference to the data provider
    this.properties||(this.properties={});
    this.properties.data||(this.properties.data=[]);
    dp?(this.properties.data=dp):(dp=this.properties.data);
    // Vars
    var CAN_SEP = 'dropdownlist'==this.type,
        n = (dp&&dp.length)||0,
        i, s;
    // Add the ListItem elems
    for (
        i=0 ;
        i < n ;
        s=(''+dp[i++]),
        this.add(CAN_SEP && '-'==s ? 'separator' : 'item', s)
        // One could improve the code to support additional
        // keys for: multicol, images, checks, etc.
    return this;
ListBox.prototype.resync = DropDownList.prototype.resync = function(/*obj[]&*/dp)
// =====================================
// Resync, or even reload, the data provider items
    this.selection = null;
    this.removeAll();
    return this.load(dp||null);
ListItem.prototype.get = function()
// =====================================
// Return an object instance from the DP (behind this ListItem)
    return this.parent.properties.data[this.index] || null;
From that point, what could the client code look like? We basically have two options:
#1 The process is non-modal and then the external object will invoke List.resync(…) when required; in this case it MUST have a reference to the widget.
#2 The process is modal, meaning that the 'external' object in fact is entirely interacted from the UI (e.g. via a button click); in that case no external reference to the list widget is actually required since the UI module itself knows exactly when a List.resync() is required, so why should it delegate the job? Here is a basic example in such a context:
// Let's have some arbitrary 'OOP' stuff available
var MyClass = function(uid,str)
{   // constructor
    this.id=uid||0;
    this.rename(str||'');
    // various methods
MyClass.prototype.rename = function(str){ this.name=str||'<unknown>'; };
    // toString()
MyClass.prototype.toString = function(str){ return this.name; };
var myDataProvider = [
    // some array of instances
    new MyClass(3, "Name 3"),
    new MyClass(5, "Name 5"),
    new MyClass(7),
    new MyClass(11, "Name 11, OK?")
var processChanges = function()
{   // emulate various changes in the data provider
    myDataProvider[0].rename("New name (3)");
    myDataProvider[2].rename("Finally Born 7");
    myDataProvider[myDataProvider.length] = new MyClass(13, "Did you miss 13?");
    myDataProvider[myDataProvider.length] = new MyClass(17, "Hello 17");
    myDataProvider.splice(1,1);
// Now the User Interface:
var w = new Window('dialog', "Example"),
    lb = w.add('listbox').load(myDataProvider),
    b = w.add('button', undefined, "Test Changes!");
lb.onDoubleClick = function()
    var someInstance = this.selection.get();
    alert( "My secret UID is: " + someInstance.id );
b.onClick = function()
    processChanges();
    lb.resync();
w.show();
Does it make sense?
@+
Marc

Similar Messages

  • HTML equivalent of ScriptUI ListBox?

    Hello,
    forgive my ignorance: what is in the HTML land the proper way to emulate good old ScriptUI Listbox component?
    I thought to use <select> specifying the size property, like:
    <select size=3>
      <optgroup label="Swedish Cars">
        <option value="volvo">Volvo</option>
        <option value="saab">Saab</option>
      </optgroup>
      <optgroup label="German Cars">
        <option value="mercedes">Mercedes</option>
        <option value="audi">Audi</option>
      </optgroup>
    </select>
    which gives:
    but it looks quite primitive compared to ListBox (no header, no columns, etc). Am I missing a different element which could fit better?
    Thank you!
    Davide Barranca
    www.davidebarranca.com
    www.cs-extensions.com

    Sorin, at the moment you can only pass string values between JSX and an HTML extension / AngularJS. With complex javascript objects this is usually done with the JSON.stringify function.
    Sadly, Extendscript does not support JSON.stringify at the moment.
    I went through the work of building my own Extendscript stringify function a few months ago and I'll go ahead and post it here. I've been meaning to refactor this and make it smaller, but it works just fine, though it could possibly be more efficient.
    function BuildJSONArray(arrayObjectList)
        var preString = '[';
        var postString = "";
        if(arrayObjectList.length > 0)
            for(var i = 0; i < arrayObjectList.length; i++)
                if( Object.prototype.toString.call( arrayObjectList[i] ) === '[object Array]' )
                    if(arrayObjectList[i].title != undefined)
                        preString += '"' + arrayObjectList[i].title + '":';
                    preString += BuildJSONArray(arrayObjectList[i]); //recursion is FUN!
                else if( Object.prototype.toString.call( arrayObjectList[i] ) === '[object Object]' )
                    preString += BuildJSONObject(arrayObjectList[i]);
                else
                    preString += arrayObjectList[i].toString() + ",";
            postString = preString.substr(0, preString.length - 1);
        else //exception for an empty array
            postString += '[';
        postString += ']';
        postString += ',';
        return postString;
    function BuildJSONObject(objToBuild)
        var preString = '{';
        var postString = "";
        for(var key in objToBuild)
            if(objToBuild.hasOwnProperty(key) == true)
                preString += BuildJSONProperty(key, objToBuild[key]);
        if(preString == '{') //exception for an empty object
            postString += preString;
            postString += '},';
        else
            postString = preString.substr(0, preString.length - 1);
            postString += '},';
        return postString;
    function BuildJSONProperty(propToBuild, valOfProp)
        var propJSON = '"';
        propJSON += propToBuild.toString();
        propJSON += '":';
        if(typeof valOfProp == 'string') //wrap in double quotes if it's a string
            propJSON += '"';
            propJSON += valOfProp;
            propJSON += '"';
        else if( Object.prototype.toString.call( valOfProp ) === '[object Array]' ) //array exception
            propJSON += BuildJSONArray(valOfProp);
            propJSON = propJSON.substr(0, propJSON.length - 1); //remove the comma, as one is added at the end of this function
        else if( Object.prototype.toString.call( valOfProp ) === '[object Object]' ) //object exception
            propJSON += BuildJSONObject(valOfProp);
            propJSON = propJSON.substr(0, propJSON.length - 1); //same idea...removing the comma
        else
             propJSON += valOfProp;
        propJSON += ",";
        return propJSON;
    HOW TO: Put the javascript objects you want to stringify into an array and call BuildJSONArray( ). It will return a string. Pass that string to your extension and rebuild it as javascript using a simple JSON.parse( ) function. Boom - done. Now you can implement ng-grid and other angular things.

  • Matrix  LinkedButton how to link to different object?

    I have a matrix , i would like to like specific colum Say column1 to
    multiple object, meaning every row will link to different object, is that possible?
    I know how to link a coulmn to a Linked object
    oColumn = oColumns.Item("column1")
    oLink = oColumn.ExtendedObject
    oLink.LinkedObject = SAPbouiCOM.BoLinkedObject.lf_GLAccounts
    what i want is based on certail condition
    row1, coulumn1 link to  lf_Invoice
    row2, coulumn1 link to  lf_PurchaseInvoice
    Is that possibel?

    i think u can use Item Event Before Action=True to solve it
    code below is what i'm using
    If pVal.ColUID.Equals("DocNum") And pVal.EventType = SAPbouiCOM.BoEventTypes.et_MATRIX_LINK_PRESSED Then
             sObjectType = oGrid.DataTable.Columns.Item("ObjType").Cells.Item(pVal.Row).Value
             oEditTextColumn = oGrid.Columns.Item("DocNum")
             oEditTextColumn.LinkedObjectType = sObjectType
    End If

  • Linking two ODS objects using a multiprovider

    Hello Gurus,
    I need to link two ODS objects and both are having 3 common characteristics and the relationship between the two objects are one to many.
    My questions would be....
    1)When the relationship is one to many can I set it up in the multiprovider to sum it up and show in the report?
    2)I have 5 other charaterstics that I need to report(Slice and dice) on, but these are not common ones to both ODS objects. Is it possible for the user to get the report based on these charaterstics also? Or do I need to make sure that these 5 also exist in both DOS objects?
    Thank you,
    DM

    Hi Sh,
    Thank you very much for your reply. But I have few concerns.
    1)One to many relationship will not have any effect on the data linking since the multiprovider clubs the key figures on common characteristics. I tried this on the system and it worked.
    2)The problem would be not having similar characteristics on both infoproviders. So if I want to report on the chars individually it will have a problem( Will come as non assigned values)
    But the documentation says the multiprovider supports Homogenous and Heterogeneous cases. Please refer the following link.
    http://help.sap.com/saphelp_nw04/helpdata/en/52/1ddc37a3f57a07e10000009b38f889/frameset.htm
    I am not sure what I can do now....whether to get all the characteristics in both infoproviders by enhancing the them. Or is there another way?
    And lastly the scenario I am looking at is billing and cost of goods. So I might find records in cost of goods which may not have corresponding records in billing.(There can be goods in stock which need to be billed)The problem would be the way multiprovider link records(union) so it will have all the records from both sides even if they do not correspond to each other.
    Let me know what you think.
    Cheers,
    DM

  • How to populate table rows with selected listbox items?

    Hello,
    I am trying to populate a table with selected listbox items. Each item should be a new row in the table. The picture below is the listbox and table I am using. I need to get the selected name to populate the Attendee column of the table when the user clicks the Add button. How do you do this with mutltiple attendees selected?
    Thank you,
    Angie

    So you're considering the fact the if the user clicks the button twice, the name will appear twice and you don't want this, right?
    Then you must check if any value is the same than the one you are about to add in the row..
    for (var i = 0 ; i < ListBox1.length; i++){
         if (ListBox1.getItemState(i) == true){
              for (var x = 0 ; x < Table1._Row1.count; x++){
                   var boNewAttendee = true;
                   var strAttendee = Table1.resolveNode("Row1[" + x.toString() + "]").txtAttendee;
                   var newAttendee = ListBox1.getDisplayItem(i);
                   if (strAttendee.rawValue == newAttendee){
                        boNewAttendee = false;
                        break;
              if (boNewAttendee){
                   txtAttendee.rawValue = ListBox1.getDisplayItem(i);

  • How to link asset with purchase order and PO Item.

    Hello,
           I have to generate a report which contains columns
    Asset No , po no(ebeln) ,PO Item(ebelp),Material no etc
    My query is how to link asset with purchase order and      PO Item.
    I am selecting asset and po no. from anla  but how to get
    po item no(ebelp)?
    po line item is important in this report because every line item has differrent asset and material no.
    i tried to match asset no in mseg table but i am not getting asset no in mseg .
    how should i proceed ?

    Thanks Thomas & Srimanta for the quick response.
    When I checked EKKN table by entering PO there is no asset no. in anln1 field.
    Also I would like to add that, In me23n for a PO, account assignment category we are entering 'F' for internal order settlement.
    Where can i find the link between asset and po no(ebeln) and po item(ebelp)?
    Regards,
    Rachel
    Edited by: Rachel on Aug 11, 2008 7:23 AM

  • Object Types--Link to business object in SBWP

    Hi All,
    In SBWP, there is an option under path Document>Create Attachment>Link to business object, in this list there is no Purchase Order,Purchase Requisition, Maintenance work order.
    Need to know how to add these business objects to this list.
    Thank You,
    Manoj

    Hi
    check the following settings
    SPRO--> cross Appl  component>Document management>Control data>Define document types-->select doc type >define  object link--->enter PORDER     Production Order
    Regards
    Sujit

  • Config JNDI and link to resource object name in WL10.0

    How to add a JNDI to JNDI tree and link to an object name in WebLogic? I am trying to like a commonj WorkManager to JNDI resource so the WorkManager can be used in client or j2ee application through JNDI lookup.
    Thanks,

    - Make sure you are using the latest build of WLS plugin.
    - Get the WeblogicBridgeConfigInfo output and check if the connection to wls servers is OK.

  • Opening Linked Excel OLE Objects in Forms 6i

    Hi,
    I have a linked Excel OLE object which is populating properly into an OLE container. However, I cannot open the file to save a local copy, as I would a non-linked Excel OLE object. If I right-click on the linked OLE object choose copy, I can paste the data into a spreadsheet, but it appears as an image, rather than as regular tabulated data. Is there anyway to open the file normally?
    Thanks in advance.

    Hi Shay,
    Thanks for the reply but i was unable to register to metalink. they need some support agreement code which i do not have. Can you please give me some more information on how to use that.
    waiting for an early reply.
    Warm Regards
    Vivek Bajaj

  • Link with SAP objects documents already stored in Docuemntum

    Hi all,
    I am working in the configuration of archivelink between SAP RE-FX and Documentum with Object Type BUS1503.
    I am able to store documents from SAPGUI in Documentum but now I would like to do the other way around. It means, documents already stored in Documentum I want to link them to this object Type to been able to display them from SAP-GUI. Where can I find documentation about this? I ahve been checking but I can not find anything.
    I have no access to Documentum itself so it is quite difficult for me to check this other way around.
    Thanks
    Diana

    Hi Diana,
    Chekc whether object links available in documentum or not? I am quite doubtful about the feathure.
    If not then access from SAP GUI and link to this object as you don't have access to documentum.
    I hope this can help better.
    BR,
    Ravindra

  • Executing listbox items according to loop

    I am making a vi in which we need to execute listbox items according to loop values defined at the begining( shown in the image attached below) , it's like that we start a loop with some values in it e.g loop(2,4,5) and loop ends with END string and all the items between loop and END we need to execute number of times the values we have defined within loop , e.g in this case since only three values are there within loop 2,4,5 so any items present between loop and END we need to execute 3 times, it could be nested loop also, we tried so many solutions but not getting how to do this, some guidance would be great help.
    function of the values defined within loop bracket is that we are having instryment list defined within loop and End and we having kept one constant x with every instrument , this x ( and the values defined within loop) are different voltages, x would be replaced every time by the newq loop value until all values are not executed.
    below i am attaching the sequence list image. 
    Attachments:
    sequence list.png ‏76 KB

    Ritu wrote:
    i am doing auto indexing but it not working correctly, below attached is the image of what i am doing.
    Like this.  (However you'll need more algorithm for this to work in nested loops - you'll have to keep a track of outside loop iterations while you execute inside loops.)
    -DP
    New Controls & Indicators made using vector graphics & animations? Click below for Pebbles UI

  • Can we link two business objects  in workflow?

    Dear All,
    Can we link two business objects  in workflow?My problem is that I have to take a standard BO for triggering my z workflow .But later  in one step  I am using BO which is Z as I am calling a standard Sap transaction in one of the method inside Zobject.
    Please let me know how to go for it .
    Kind Regards,
    Anshu Kumar

    Hi Anshu,
    You can use the standard BO as the BO for your workflow and trigeger the workflow from its event. To pass values from the standard BO to the custom BO used in the activity step, you need to do proper binding between the std and custom BO in the activity step.
    Do proper binding between event -> workflow -> task container.
    For assistance on binding in workflows refer to the followng links:
    http://****************/Tutorials/Workflow/Workflow.htm
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/workflow%252bscenario
    /people/sapna.modi/blog/2007/02/19/workflows-for-dummies--introductionpart-i
    Hope this helps!
    Regards,
    Saumya

  • Email Link... and Email Image menu items don't work.

    Suddenly, about a week ago, the Email Link... and Email Image menu items stopped working. Problem seems to be on only one login on one of my three machines. The rest seem to be OK.
    Using FF 19.0 and TB 17.0.3 under Windows 7.
    Any ideas?

    Thank you. Although I had already checked the MailTo: application and found it set to "Use Thunderbird (default)", clearing that association and setting it to "Always Ask" jarred things loose. When I set it back to T-Bird, it worked again.
    Again, thanks for the nudge.

  • Link Between Business Object and Transaction

    <b>How is Business Object linked to transactions?</b>
    For example, how is business object BUS2032 (Sales order) linked to transaction VA01 (Create sales order)?

    Hi Ben,
    I'm not sure that you link a business object and a transaction code explicitly. Normally in the business objects methods you have coded what transaction code should be called. Therefore if you use the methods of the business objects it then knows what transaction to call.
    Conversely on the workflow side you will find that down in the depths of the coding for VA01 (as an example) it calls workflow function modules and raises events. When doing so it provides the business object id and key to the business object (i.e. the sales order number). Indirectly I guess the change documents that are raised for most things in SAP like sales documents are uniquely identified and therefore can also be translated to the business object key (e.g. sales documents will have their own change document type).
    A brief example in my 4.6c system can be found in include LIEDPF4C in the form finsta_kontoauszug_buchen with a call to function SAP_WAPI_CREATE_EVENT. You see the the parameter "object_type" has a variable passed to it "objtype_finsta". If you drill back on objtype_finsta you see that is hardcoded to the value BUS4499.
    I guess you could say the developer of the business object knows what transaction codes the business object should use and the developer of the code in the transaction code knows what business objects he should be raising events for if necessary.
    Hope this helps.
    Regards,
    Michael

  • Linking External Business objects of ECC to Case in Webclient

    Hi guys,
    i have a requirement where i need to link external business object like BUS2080(Service Order),BUS2088(Service Notification) in record of UI component CRMCMP_CMG(CRMCMP_CMG/RecordTree ).
    I have done the below  configuarions:
    1) where i have created registry entry for the external object types.Defined the element types for the external objects.
    2) then i have done " Assign Element Types and Business Object Types to a Process'.
    3)Also implemented the BADI  CRM_CMG_ADD_OBJECT to link the external  business objects.
    Now i want to see these external business objects in the wbclient component  view CRMCMP_CMG/RecordTree.
    But couldn't get the objects there  only i can find the standard record model with CRM Business objects only.
    If any one  has worked in case management in webclient to link the objects please share your inputs .Also if anybody have any idea please share.
    Regards
    Snehasish

    Hi, did you find a solution already to your problem? We are facing the same problem.
    In the backend transaction (CRM in Sapgui) it's working fine, but in the CRM_UI transaction the reference object cannot be selected from the dropdown menu...
    Please let me know if you have a solution.
    Best regards,
    Marcel

Maybe you are looking for

  • Mail.app - Multiple mailboxes on same AD-account

    Mod may move my question the the right section of the community. Hello, Trying to set up my work-mailboxes in the Mail-app. I have my personal email ([email protected]) but also several other mails (for example: [email protected] och [email protected

  • Handling Special Character in SAP PI

    Hi, I have a file to proxy scenario where I have used a complex UDF to get proper data at receiver side. Now, from the sender side I am getting  some special characters in the files and due to this the whole file is getting failed with mapping error.

  • Updating the G/L Accounts

    When Installing SAP B1 in Clients place, we would like to up date previous data into SAP B1. Client does not have any ERPsystem, How can I import the Existing Data Available in different books. At time of Importing what are the Basic factors to be co

  • Search for file types in multiple folders

    Hello, I would like to copy all jpg images from around twenty folders into one folder. In Windows you simply go to the root folder and search for *.jpg, and it will list all jpg files in these twenty folders. How can I achieve the same effect in OSX?

  • Running DBMS_SQL.EXECUTE in Oracle Select Statment

    HI i have table Emp which has 3 column namely name,st_date and end_date. table has 3 records as below: name st_date end_date X sysdate+10 sysdate+50 Y sysdate+12 sysdate+30 Z sysdate+15 sysdate+35 Now if i run the run select statment select * from em