syntax question

here is my code:

newSystem.setAttribute("where","[MIN_DCP].id = '"+this.getProperty("id")+"'");

I'm looking to add the OR condition to it.

ex.

where min_dcp.id = this.getProperty("id") OR min_dcp_parent_adp = this.getProperty("id") 

ty

  • Hello,

    There's a few different ways to go about doing an OR condition like this. 

    First off, where clauses do allow you to use OR conditions by simply throwing an OR between the two conditions. When working with OR clauses, I'd recommend taking a look at standard SQL syntax. There are some measures in place to avoid SQL injection so not all the standard SQL syntax is supported, but use of AND and OR seem to be fine from my tests.

    Item whereClause = inn.newItem("Part", "get");
    whereClause.setAttribute("where", "[Part].id = '4ADEC55B349C446AAD8BD4A80699345F' OR [Part].id = '612728398EA142BF98AC7751F310B9FF'");

    Secondly, since you're querying on IDs, you can take advantage of the idlist attribute instead of the where attribute. This allows you to pass in a comma separated list of IDs to filter your query by.

    Item idlist = inn.newItem("Part", "get");
    idlist.setAttribute("idlist", "4ADEC55B349C446AAD8BD4A80699345F,612728398EA142BF98AC7751F310B9FF");

    Lastly, I'd recommend checking out the Programmer's Guide for some additional ways to do logical queries like this. The other ways are not suited for IDs since there are easier approaches, but I want to mention them in case you have similar requirements for other properties in the future like if you want to search for an item with one of two keyed_name's. 

    Chris


    Christopher Gillis

    Aras Labs Software Engineer