SAP C4C OData服务的filter,客户端分页和排序的使用方式

假设系统里已经有许多的Lead历史数据,而我们正在进行的微信小程序和C4C集成的项目里,又创建了许多新的Lead数据。如何将这些新的在微信小程序里调用OData服务创建的Lead数据同老的历史数据做区分呢?

(1) 在C4C Sales Lead页面里,通过Source字段来标明Lead的来源。

对于AI Card项目来说,所有的Lead经由微信小程序创建,因此调用OData API时,SourceCode指定为“Wechat Social Channel”的代号:Z01

这样,在读取操作时,使用 f i l t e r = S o u r c e C o d e e q Z 0 1 S o u r c e C o d e Z 01 l e a d . 使 filter=SourceCode eq 'Z01'操作,能取出系统所有SourceCode为Z01的lead. 再使用 inlinecount=allpages,能一并返回SourceCode为Z01的Lead一共有多少个。

最后的url如下:
https://my500.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection?KaTeX parse error: Expected 'EOF', got '&' at position 27: …ceCode eq 'Z01'&̲inlinecount=allpages

结果如下:

截至2020年3月20日12:23PM为止,在系统上经由微信小程序创建,Source Code字段为Z01的Lead总共有6个。

如果系统里满足这个条件的Lead越来越多,调用OData服务后,会造成规模巨大的数据量从服务器发送往消费端,所以建议使用客户端分页方式读取数据。

首先获取满足SourceCode为Z01的lead个数:

https://my500.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection/ c o u n t ? count? filter=SourceCode eq ‘Z01’

假设返回结果数为1000, 我们可以在客户端进行分页读取,每页读取的个数可以客户端自行决定,比如每次读取20个。

第一页的读取请求:

https://my50.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection?KaTeX parse error: Expected 'EOF', got '&' at position 24: …ourceCode eq ''&̲orderby=CreatedOn desc&$top=20

20个Lead返回:

第二页:即第21到第40个:
https://my50.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection?KaTeX parse error: Expected 'EOF', got '&' at position 24: …ourceCode eq ''&̲orderby=CreatedOn desc&KaTeX parse error: Expected 'EOF', got '&' at position 8: skip=20&̲top=20
第三页:即第41个到第60个
https://my500.c4c.saphybriscloud.cn/sap/c4c/odata/v1/c4codata/LeadCollection?KaTeX parse error: Expected 'EOF', got '&' at position 24: …ourceCode eq ''&̲orderby=CreatedOn desc&KaTeX parse error: Expected 'EOF', got '&' at position 8: skip=40&̲top=20

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

发布了7153 篇原创文章 · 获赞 654 · 访问量 122万+

猜你喜欢

转载自blog.csdn.net/i042416/article/details/104988382