0

I have a very simple query:

var where = "<Where>";
var decoded = decodeURIComponent(searchKey);
where += "<Contains><FieldRef Name='Nr' /><Value Type='Integer'>" + decoded + "</Value></Contains>";
where += "</Where>";

var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var list = web.get_lists().getById("D7688EA6-B43D-47AE-A3C9-C68A4DAADAD1"); 
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query>" + where + "</Query></View>");
var kurse = list.getItems(camlQuery);
ctx.load(kurse);
ctx.executeQueryAsync() //rest of code omitted

The result is an Exception:

"Exception from HRESULT: 0x80131904"

Nr is an integer field. If I query on another field, e.g. Title, it works. I noticed this behaviour after migrating from SharePoint Server 2016 to 2019.

Any ideas?

1 Answer 1

1

As per the documentation, Contains element (Query),

Contains searches for a string anywhere within a column that holds Text or Note field type values.

So, you cannot use it directly on number columns.

Workaround:

Create a new calculated column in list with return type "Single line of text" which will have same value as of the number column.

Then, use your CAML query filter on the calculated text column instead of number column.

4
  • You can use TEXT function in calculated column to get text string from number column. Oct 4, 2022 at 8:47
  • 1
    I wonder why It worked until I migrated to 2019. Anyway, thanks.
    – Emaborsa
    Oct 4, 2022 at 8:48
  • You're welcome! Oct 4, 2022 at 8:50
  • 1
    I prefer to use CSR.
    – Emaborsa
    Oct 4, 2022 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.