This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - how to exclude a value in a filter ?

Anita - Wednesday, December 8, 2010 9:13 AM:

Hello all,

Does anyone know how to exclude a value in a filter in a simple search?

In advanced search I would select the operation "not like". But I have to use it in a javascript methode where a simple search is used. To set a value in the filter I use the following code:
var Filter=new Object();
Filter["state"]={filterValue:"Released",isFilterFixed:true};
return Filter;

But how can I set the filter to show all states but e.g. "Released"?

Thanks for your help.



brueegg - Wednesday, December 15, 2010 6:35 AM:

Hello

I have exact the same problem. Does anybody has a solution on this?

I need to have a search filter (onSearchDialog event) set to advanced. Is that somehow possible?

Is there another solution how I can filter objects? I need to show i.e. objects with the status "created" and "review" but not "released".

 

Thanks for a reply



Brian - Wednesday, December 15, 2010 7:08 AM:

 This code restricts the user to the items returned by the query in "qry1"

The query is executed including all of the restrictions you need to make and  then the "Idlist" is built up with the "id's" of the Items (in this case Documents) that are returned from the search.

This idlist is then passed out of the method as an attribute of the "inargs" item that was passed in with the context item.

You should be able to substitute your query in for qry1 and this code should work for you.

 

// Called from related_id grid cell onSearchDialog event of Outoing Document

// Relationship item type.

// It is only valid for documents with the following criteria to be selected

 

// Status is "released"

// There is no "customer_response" item attached to the Document

// The flag "customer_approval_required" must be checked (true)

//

 

// Use a filtered item browser

if (!inArgs.itemContext)

    {return;}

var qry1 = this.newItem("Document", "get");

qry1.setAttribute("where", "[Document].state='Released' AND [Document].customer_approval_required='1' AND ([Document].customer_response IS NULL)");

 

var res = qry1.apply();

 

if (res.isEmpty())

{

    inArgs.QryItem.item.setAttribute("idlist","");

    return ("");

}

if (res.isError()) {return res;}

var count=res.getItemCount();

var idarray=new Array();

for (i=0;i<count;i++){

  var item=res.getItemByIndex(i);

  idarray[i]=item.getID();

  var idlist=idarray.join(",");

}

inArgs.QryItem.item.setAttribute("idlist",idlist);

return("");

 

Hope this helps.

Brian.



Brian - Wednesday, December 15, 2010 7:19 AM:

Sorry about the first post. This forum mutilates code sometimes when you post it.

I have edited the original post to give correct code.

Cheers,

Brian.



Anita - Monday, December 20, 2010 10:31 AM:

Hello Brian

Thanks for your code. It works fine this way if there are some items to find. But if there are no items where the search query fits, users can get ALL items by clicking the "Run search" button again. Is there a way to prevent this?

I already tried this:

if (res.isEmpty())  {
    inArgs.QryItem.item.setAttribute("idlist","");
    return res;
}

Any ideas?



brueegg - Thursday, December 16, 2010 8:50 AM:

Thanks for the example code. This helped me a lot.

Greetz

Björn



Brian - Tuesday, December 21, 2010 10:18 PM:

Hi Anita,

You could try something like this:

if (res.isEmpty())

{

    top.aras.AlertError("There are no suitable items to display");

    var Filter = new Object();

    Filter["state"]={filterValue:"Released", isFilterFixed:true};

    return Filter;

}

Set the "normal" filter to something that you know won't return a result and set the filterFixed = true and display a notice to the user that there are no items that match.

Not sure at this stage how to automatically close the search dialog which would be the ideal solution. This way the user has been advised that there is nothing to find and can't change the filter.

Hope this helps.

Brian.



Anita - Wednesday, December 22, 2010 4:19 AM:

Yeah, that works! Thanks a lot!

Greetz Anita

 

Here is the code:

if (!inArgs.itemContext)  {return;}

var qry1 = this.newItem("CAD_Document", "get");
qry1.setAttribute("where","[CAD_Document].state='Released' AND ( [CAD_Document].classification_selected='Model' OR [CAD_Document].classification_selected='Assembly' )");

var res = qry1.apply();
if (res.isEmpty())
{
    top.aras.AlertError("No items could be found");
    var Filter = new Object();
    Filter["state"]={filterValue:"Released", isFilterFixed:true};
    return Filter;
}

if (res.isError())  {return res;}
var count = res.getItemCount();
var idarray = new Array();
for (i = 0; i < count; i++) {
    var item = res.getItemByIndex(i);
    idarray[i] = item.getID();
    var idlist = idarray.join(",");
}

inArgs.QryItem.item.setAttribute("idlist",idlist);

return res;



AbhishekSrivastava - Wednesday, March 30, 2016 1:18 AM:

Hi Brian,

i want to filter my dropdown value in Test Item Type  fetch from Project Item Type regarding Project Name. So below code is to fetch value from Project Item Type to Test Item Type in a dropdown way,

var div_id = getFieldByName("similar_project").id;
var control_id = div_id.substring(0, div_id.indexOf("span"));
var select = document.getElementById(control_id);


//...Replace this with a call to a external datasource...
//get Customer
var returnItm = document.thisItem.newItem("Project", "get");
returnItm.setAttribute("select", "name");
returnItm = returnItm.apply();

//populate the select list with options
for (var i=0;i < returnItm.getItemCount(); i++)
{
    var project = returnItm.getItemByIndex(i);
    select.options[i]=
    new Option(project.getProperty("name"),
    project.getProperty("id"));
}

But i want to filter like

if i select in Classification property of Test Item Type is Plastic then only Plastic project comes in dropdown.

if i select metal then Only metal project name comes in dropdown.

So how will i filter.

Kindly request to help me on that issue.

Thank You

Abhishek Srivastava