cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Infotable filter AND/OR

svisveswaraiya
17-Peridot

Infotable filter AND/OR

Hi,

I am using the infotable filter functions, when I use single filter it works but when I try to nest AND/OR it doesn't work. I have Activity area, start time, end time and shift name as inputs. I wanted to nest like

(Activity area or (Start time and End time and Shift Name))

I have gone through the examples given in help by ptc but when I try it, it doesnt execute the way I want. It throws error like must bind data shape but I have already binded a datashape. 

Please help me with where I am going wrong.


//call close session
//me.getcloseSession();
var headers = { "Content-Type": "application/json"};

var url = "http://"+ me.host + ":" + me.port + "/api/shifts/"+parameterID;

var params = {
proxyScheme: undefined /* STRING */,
headers: headers /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: undefined /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: url /* STRING */,
timeout: 15 /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: undefined /* STRING */,
domain: undefined /* STRING */,
username: undefined /* STRING */
};

// result: JSON
try {

var json = Resources["ContentLoaderFunctions"].GetJSON(params);

var param1s = {
infoTableName : "InfoTable",
dataShapeName : "Ferrara_Shiftnfo_DS"
};
var newInfo = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(param1s);
var tStartTime;
var tEndTime;

for(var i=0; i<json.Items.length; i++)
{

if (json.Items[i].Shift.StartTime.length > 20)
{
tStartTime = parseDate(json.Items[i].Shift.StartTime.replace("T", " "), "yyyy-MM-dd HH:mm:ss.SSS");
}
else
{
tStartTime = parseDate(json.Items[i].Shift.StartTime.replace("T", " "), "yyyy-MM-dd HH:mm:ss");
}


if (json.Items[i].EndTime.length > 20)
{
tEndTime = parseDate(json.Items[i].EndTime.replace("T", " "), "yyyy-MM-dd HH:mm:ss.SSS");
}
else
{
tEndTime = parseDate(json.Items[i].EndTime.replace("T", " "), "yyyy-MM-dd HH:mm:ss");
}


//
if (json.Items[i].Shift.Name != null &&
json.Items[i].Shift.Name != '' && json.Items[i].Shift.Name != ' ' && json.Items[i].Shift.Name.length != 1)
{
// if (json.Items[i].ActivityAreaName == activityName)
{
newInfo.AddRow({parameterSet:json.Items[i].Id,
activityArea:json.Items[i].ActivityAreaName,
WorkCellConfigId: json.Items[i].WorkCellConfigId,
ActivityAreaId: json.Items[i].ActivityAreaId,
shiftName:json.Items[i].Shift.Name,
startTime:tStartTime,
endTime:tEndTime,
State: json.Items[i].State,
Number: json.Items[i].Shift.Number

});

}
}
// }
}
result1 = newInfo;
var query = {
"filters": {
"type": "OR",
"filters": [
{
"type": "AND",
"filters": [
{
"type": "EQ",
"fieldName": "startTime",
"value": startTime
},
{
"type": "EQ",
"fieldName": "endTime",
"value": endTime
},
{
"type": "EQ",
"fieldName": "shiftName",
"value": shiftName
}
]
},
{
"type": "EQ",
"fieldName": "activityArea",
"value": activityName
},
]
}
};

var params2 = {

t: result1/* INFOTABLE */,

query: query /* QUERY */

};

 

var result2 = Resources["InfoTableFunctions"].Query(params2);

var params4 = {

t: result2/* INFOTABLE */,

query: sort /* QUERY */

};

// result: INFOTABLE

var result = Resources["InfoTableFunctions"].Query(params4);
}
catch(err)
{
me.getCloseSession();
}

 

Thanks in advance.

4 REPLIES 4

@svisveswaraiya 

 

It might be useful to break down your code and work only with the query to make sure there is a problem with it.

I have done a simple test with just that query and it looks like it works for me.

I have attached the sample entity I used, I just entered a few random values in the QueryIT infotable in properties page and ran the query with some various values, and the output was as expected.

Might be interesting for you to check with that entity to confirm if you see something odd or if it works ok... then maybe the problem is something else or may need to try with data closer to what you actually have - might be an issue depending on the type of data.

 

Hope this helps

Christophe 

Hi @cmorfin,

Thanks for your swift response.

The entities you sent throws error and did not get imported for me.

 Hi @cmorfin ,

The filter should work if I just pass activityArea and other inputs as null right? Because am looping a OR condition for it.

Hi @svisveswaraiya 

I have attached a new entity file, should import ok this time.

Note it does not work for me if there is no value for the other fields, so probably not a good idea to pass null.

 

Christophe

 

Top Tags