Combination of OData filter functions (replace inside startswith)

Discussions about Cross-site Lookup
Locked
ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

20 Jul 2018

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?

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

23 Jul 2018

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.
Cheers

ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

26 Jul 2018

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....

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

27 Jul 2018

Dear ragesoft,
Actually really glad to hear that you've found a solution. Great work!
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests