Page 1 of 1

Combination of OData filter functions (replace inside startswith)

Posted: 20 Jul 2018
by ragesoft
Hi,

we've to a column with chapter numbers. This column is formated as s string and is designt to extend the numbers with leading spaces, so each chapter / subchapter is 4 chars log.
e.g.: " 3. 2. 1."

if i want to filter by chapter and "startswith", the user has to insert the spaces in the csl as well....
OData offers a function "replace". So i thought i can use something like:

startswith(replace(Chapter,' ',''),'" + encodeURIComponent(term) + "')

but this only results in an error.
How can i filter and ignore whitespaces?

Re: Combination of OData filter functions (replace inside startswith)

Posted: 23 Jul 2018
by Nikita Kurguzov
Dear Ragesoft,
This might be doable, but will require you to have at least one Or filter operation, so you'll need to check multiple conditions. You'll also need to use JavaScript to dynamically add spaces to the correct places in the string, then encode it. This is no easy task, but might be possible.

What you might do here is launch a Workflow or Flow which will remove spaces from the column, and re-save value to a new column in the same list. Then filter by the current column OR by the newly created one. This should be the simplest solution possible.

Re: Combination of OData filter functions (replace inside startswith)

Posted: 26 Jul 2018
by ragesoft
I've solved the problem for now by just adding leading whitespaces :)

Code: Select all

var termSplit = term.split(".");
	$.each(termSplit,function(index, value){
		if(value){
			var a = (value.length<4?5-value.length:0);		
			termSplit[index] = new Array(a).join(' ') + value;
		}
	});
	var termSpaced = termSplit.join(".");
And in the filter i have two times "startswith" and "OR" :) not best, but working solution....

Re: Combination of OData filter functions (replace inside startswith)

Posted: 27 Jul 2018
by Nikita Kurguzov
Dear ragesoft,
Actually really glad to hear that you've found a solution. Great work!