0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SmartDB】アクション部品(API連携)で文書リンク(配列)をPOSTする

0
Posted at

はじめに

SmartDBのアクション部品(API連携)では、文書リンクの一覧をJSON形式でPOSTしたい場面があります。
ところが、Velocity環境で使える util.json が利用できなかったり、ループ制御が意図通りに動かなかったりと、地味にハマりどころの多いポイントです。
本記事では、これらの制約を回避してJSON配列を生成する実装例を紹介します。

実装コード

## 文書リンク一覧を取得
#set($linkList = $document.getLinkedDocumentList(部品コード))

## 2件目以降の先頭にカンマを付けるための区切り文字(初回は空)
#set($comma = "")

## JSONを生成
{
  "links": [
    #foreach($ref in $linkList)
      $comma"${ref.binderId}-${ref.recordId}"
      #set($comma = ",")
    #end
  ]
}

ポイント

  • 文書リンク一覧は $document.getLinkedDocumentList(部品コード) で取得できる
  • 配列をそのまま送信すると各要素に " が付かない形式になるため、標準JSON形式へ整形する必要がある
  • util.json が使えないため、自力でJSON文字列を組み立てる
  • $foreach.hasNext が使えないため、#set($comma = ",") で2件目以降の先頭に "," を付与する

おわりに

工夫次第で柔軟にデータを整形できます。外部システムとの連携に、ぜひ活用してください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?