Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way o check if item exist #76

Open
CribAd opened this issue Aug 8, 2024 · 2 comments
Open

Best way o check if item exist #76

CribAd opened this issue Aug 8, 2024 · 2 comments

Comments

@CribAd
Copy link

CribAd commented Aug 8, 2024

Hi all,

Nice library, thanks!

I want to check if an Item with a specific ItemCode exists in SAP B1.

I do https://[servicelayer]/b1s/v1/Items('12345')?$select=ItemCode. When ItemCode 12345 exists, I will get a successful response. But when it does not exist I get an unhandled exception. Of course I can resolve this with a try-catch, but that doesn't sound like the most smooth way to check if a specific item exists. What is your advise?

@jmartins-sh
Copy link

jmartins-sh commented Aug 8, 2024

Hey @CribAd how's it going? Hope well!

Actually you probably got a 404 status code, which will throw an exception. If you like you can modify this behavior during the request, using the extension method called .AllowHttpStatus(statusCode), in your case 404 (NotFound).

//public static SLRequest AllowHttpStatus(this SLRequest request, params HttpStatusCode[] statusCodes)

var item = await serviceLayer.Request("Item","12345").Select("ItemCode").AllowHttpStatus(HttpStatusCode.NotFound).GetAsync<MyItemModel>();

Using the extension method you prevent the exception in this case.

@CribAd
Copy link
Author

CribAd commented Aug 15, 2024

Thanks, that works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants