cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Cloud SDK - Execute filter with contains operator

Hi Expert,

Is the SDK filter support contains operator. For example:

.filter(
      BusinessPartner.FIRST_NAME.contains('ABC')
    )

Kind & Regards

Ethan

Accepted Solutions (1)

Accepted Solutions (1)

Junjie
Advisor
Advisor
0 Kudos

Hi Ethan,

I think you should import the function "substringOf", which I cannot find in your screenshot.

Please note:

"BusinessPartner" should be imported from the vdm module "@sap/cloud-sdk-vdm-business-partner-service", while "substringOf" is in the package called "@sap/cloud-sdk-core".

Therefore, you should import like:

var substringOf = require('@sap/cloud-sdk-core').substringOf;

You can find the documentation here.

Best regards,

Junjie

0 Kudos

Hi Junjie

It worked. Thank you so much.

Kind & regards

Ethan

Answers (2)

Answers (2)

Junjie
Advisor
Advisor
0 Kudos

Hi Ethan,

the link below shows the reason of "X is not defined".

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/Not_defined

It seems that you see the error during runtime instead of compile time.

I guess your project is not a typescript project, but a js project?

Have you import the module from the sdk?

Best,
Junjie

0 Kudos

Hi Junjie,

Yes, it is a js Project.

And i have imported the module from SDK.

Kind & Regards,

Ethan

Junjie
Advisor
Advisor
0 Kudos

Hi Ethan,

thank you for contacting us.

As announced in the new release recently, you can use the filter function with the SDK.

However, the "contains" function is introduced in OData V4, while the SDK only supports OData V2.

The workaround would be using "substringof" function.

In your case, the code snippet would be:

.filter(
  substringOf('ABC', BusinessPartner.FIRST_NAME).equals(true)
)

Please note, the order of the parameters is important.

Please let me know, if you have any questions.

Best regards,

Junjie

0 Kudos

Hi Junjie,

Thank you so much for your prompt reply.

I have tried the substringOf function. But i got this error.

Here is my code example:

try {
   var response = await BusinessPartner.requestBuilder()
            .getAll()
	    .filter(
	     substringOf('ABC', BusinessPartner.FIRST_NAME).equals(true)
	    )
	    .execute(destination);
    } catch (e) {
      return e.message;
    }

Kind & Regards

Ethan