How can you open search dialog in javascript with a filter

Hello

as per title - how can we set the filter for search dialog in javascript

var param = {
                title: title,
                aras: top.aras,
                type: 'SearchDialog',
                dialogWidth: 700,
                dialogHeight: 450,
                itemtypeName: 'Part'            
            };
wnd.ArasModules.Dialog.show('iframe', param).show("iframe", param);
Is it possible to catch an even of this dialog?
Or how can we manually run the opened dialog "search"? The dialog is an iframe and the dijits have no ids 
I managed to make it work for test case with, mind you i cannot use this in reality, scope issues
 dijit.byId("dijit_form_TextBox_0").setDisplayedValue("3*");
 dijit.byId(dojo.query('.dijitButton')[0].attributes.widgetid.nodeValue).onClick()
Thank you
Parents
  • Hello,

    It is possible to filter a search dialog by setting an onSearchDialog event on a property of an ItemType as outlined in this blog.

    When calling a search dialog from JavaScript like in your example, you can set the sourceItemTypeName and sourcePropertyName in the parameters you pass in. If an onSearchDialog event exists on the property name you pass in using these parameters, that filter will be applied to the search dialog opened by your code. For a full list of the parameters available when opening a search dialog, please see this blog post on using standard aras dialogs.

    Chris

    Christopher Gillis

    Aras Labs Software Engineer

  • Hello again Christopher, my code is below could you help me understand what i could bind the onSearchDialog event to? Dialog itself contains just a promise and dom element of dialog. And i tried to connect to the event on the node itself (but it obviously doesnt emit it)

    var param = {
                    title: title,
                    aras: top.aras,
                    type: 'SearchDialog',
                    dialogWidth: 700,
                    dialogHeight: 450,
                    itemtypeName: 'Part',
                    
                    sourceItemTypeName: 'Part',
                    sourcePropertyName: '*3'
                };
      var dialog = wnd.ArasModules.Dialog.show('iframe', param);
      dialog.promise.then(dojo.partial(callback, copy))
  • Hello,

    For this use case, we typically recommend creating a new property on the ItemType to serve as a placeholder to attach your onSearchDialog event to. This will new property is typically not intended to store any data and should be hidden from every form and grid. You can call this property something like filter_placeholder.

    Once you have this new property on the Part ItemType, you can attach your onSearchDialog to it and update your method code to use this new property's name to call the filtering event.

    var param = {
                    title: title,
                    aras: top.aras,
                    type: 'SearchDialog',
                    dialogWidth: 700,
                    dialogHeight: 450,
                    itemtypeName: 'Part',
                    
                    sourceItemTypeName: 'Part',
                    sourcePropertyName: 'filter_placeholder'
                };
    var dialog = wnd.ArasModules.Dialog.show('iframe'param);
    dialog.promise.then(dojo.partial(callbackcopy));

    Chris

    Christopher Gillis

    Aras Labs Software Engineer

  • not behind my computer but im assuming onSearchDialog is one of the aras events and not a javascript dialog events?

  • That's correct. It's an event that you can set specifically on Property items.

  • Once I'm in the method initiated by the OnSearchDialog event, how do I get properties from the item on the form/grid that initiated the search?

    For example, I want to mimic the "Pick/Replace" action in a Part BOM, but I need to set a filter using a prefix based on a property on the part in the Part BOM grid that the action was called on.

    I can't seem to find a way to access properties from any context items. All I can see is that I'm searching for a particular item type. 

    -Ken

  • I found another thread that talks about making a version of SearchDialog.html to accept a new argument. I'm not sure how to do that though. 

    How difficult would it be to build my own using a form?

  • Hello Christopher, I have a scenario now where I am trying to do something similar but have one additional condition :).

    Via an Action / Dialog in a first step I am asking the user for a target lifecycle state.  Based on that selection, I need to present a search dialog as described above, but somehow I need to pass the selected lifecycle state on to the search dialog so that it can be obtained from within the OnSearchDialog method.

    I have the search dialog opening already such that the OnSearchDialog method is triggered but all additional non-standard passed parameters seem to be discarded.

    for example:
    var param = {
      ...,
      targetLCStateNew = "<someID>"
    };

    Any suggestions on how to pass some information on to the search dialog so that it has some *context* for the OnSearchDialog method when opened from a JS method?

  • Hi JWT007,

    I want to join your question! I actually found some solution, but it doesn´t work reliable. In my case I face the problem, that end users can call the Action/Dialog from the grid but also from the Form. This variant just works when a called from Form:

    // parent.thisItem -> only available when Action was triggered from Form
    if (parent.thisItem !== undefined){
       var state = parent.thisItem.getProperty("state","*");

       // Set filter in an onSearchDialog event
       var Filter = {};
       Filter["state"] = { filterValue: state, isFilterFixed: true };
       return Filter;
    }

  • This was my first thought as well. Rather than passing the data to the search dialog event, simply look it up from the parent window that opens the search dialog. 

    To 's use case, the user is prompted to select some target life cycle state. Perhaps you could clarify how this is done. One way to do this that would make it agnostic to where this action is called from would be to direct the user to an intermediate dialog that would contain one field that lets them choose the target life cycle state and one button that launches the search dialog. From the context of the search dialog event, the parent window in this use case would be the intermediate dialog, so you could look up the value of the target life cycle that the user specified and then use that in your filter just as Angela's code does above.

    Chris

  • Hello Christopher, thanks for your response.

    Since I had no luck with the modal SearchDialog, I ended up creating a Form Dialog for this, which I then lookup and populate it with just enough information to satisfy the OnSearchDialog criteria for the Item field on that form.

    To clarify the selection of the target life-cycle state, this is also done using a form populated that is handed the response of a server method (the lifecycle information from a SQL query) and in the OnLoad this information is moved from the context into a drop-down field on the form.  I obtained the result from this dialog on "OK" and used it to ultimately feed the second custom dialog.

    My problem was with only opening a search dialog without an intermediate form.  Here it would be a great addition to pass some kind of context which could then be queried in the OnSearchDialog linked method (without using an intermediate form).

    Cheers, Jeff

Reply
  • Hello Christopher, thanks for your response.

    Since I had no luck with the modal SearchDialog, I ended up creating a Form Dialog for this, which I then lookup and populate it with just enough information to satisfy the OnSearchDialog criteria for the Item field on that form.

    To clarify the selection of the target life-cycle state, this is also done using a form populated that is handed the response of a server method (the lifecycle information from a SQL query) and in the OnLoad this information is moved from the context into a drop-down field on the form.  I obtained the result from this dialog on "OK" and used it to ultimately feed the second custom dialog.

    My problem was with only opening a search dialog without an intermediate form.  Here it would be a great addition to pass some kind of context which could then be queried in the OnSearchDialog linked method (without using an intermediate form).

    Cheers, Jeff

Children
No Data