之前做过几个项目都有saved search中使用formula搜索结果列的情况,个人感觉当同一个类型的formula结果列出现多次但formula的内容不一样的情况下很容易产生bug。

今日的例子中,在对于invoice的搜索中我使用了如下的searchColumn,对应结果中的formulacurrency和formulacurrency_1

      search.createColumn({
         name: "formulacurrency",
         formula: "{fxamount}*{exchangerate}",
         label: "Formula (Currency)"
      }),
      search.createColumn({
         name: "formulacurrency",
         formula: "{fxamountremaining}*{exchangerate}",
         label: "Formula (Currency)"
      }),

搜索结果反馈是正常的。之后我添加了两个搜索列,对应结果中的formulacurrency_2和formulacurrency_3

      search.createColumn({
         name: "formulacurrency",
         formula: "{fxamount}",
         label: "Formula (Currency)"
      }),
      search.createColumn({
         name: "formulacurrency",
         formula: "{fxamountremaining}",
         label: "Formula (Currency)"
      }),

问题来了:用于显示结果的suitelet上,4个列返回的数字是一样的,返回的都是133.14,明显不正确;但log显示的结果是正确的,如下:

{"recordType":"invoice","id":"10114392","values":{"trandate":"7/14/2021","entity":[{"value":"237539","text":"**************"}],"currency":[{"value":"4","text":"EUR"}],"tranid":"INGM000254","fxamount":"133.14","formulacurrency":"156.842","formulacurrency_1":"156.842","internalid":[{"value":"10114392","text":"10114392"}],"formulacurrency_2":"133.14","formulacurrency_3":"133.14"}}

这种情况下因为上面代码中formulacurrency_2和formulacurrency_3公式比较简单,可以直接使用字段进行搜索,避免formulacurrency的使用,即可避免问题

search.createColumn({name: "fxamount", label: "Amount (Foreign Currency)"}),
search.createColumn({name: "fxamountremaining", label: "Amount Remaining (Foreign Currency)"})

此时返回结果是正确的

{"recordType":"invoice","id":"10114392","values":{"trandate":"7/14/2021","entity":[{"value":"237539","text":"*************"}],"currency":[{"value":"4","text":"EUR"}],"tranid":"INGM000254","formulacurrency":"156.842","formulacurrency_1":"156.842","internalid":[{"value":"10114392","text":"10114392"}],"fxamount":"133.14","fxamountremaining":"133.14"}}	

问题得以解决。

如果更复杂的情况确实需要多个formula的情况呢,这种情况可以考虑把searchResult当作JSON进行处理,直接用Object[key]的方式取值。不过这种情况需要考虑未来SuiteScript更改返回结果结构的情况,方案可能随时失效。

暂时没有用过N/query处理过类似情况,如果有人做过也可以来说说。

Last modified: 01/08/2021

Author

Comments

Write a Reply or Comment

Your email address will not be published.