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?

【実験】SuiteScriptの自動生成 ーその2ー

Posted at

✅ 成功例②「承認待ち注文書をJSONで出力」

概要

ダッシュボードに表示される「注文書 承認待ち」の情報を検索し、JSON形式で出力するスクリプト。

実行したプロンプト

#NetSuiteのダッシュボード上に「注文書 承認待ち」とき記載があります
#この情報をJSONで出力するスクリプトを生成してください

生成されたスクリプト

/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(['N/search'], (search) => {

    const onRequest = (context) => {
        if (context.request.method === 'GET') {

            const purchaseOrderSearch = search.create({
                type: search.Type.PURCHASE_ORDER,
                filters: [
                    ['status', 'anyof', 'PurchOrd:A'] // 「承認待ち」ステータス
                ],
                columns: [
                    'tranid',
                    'entity',
                    'trandate',
                    'amount',
                    'status'
                ]
            });

            const results = [];

            purchaseOrderSearch.run().each(result => {
                results.push({
                    id: result.id,
                    tranId: result.getValue('tranid'),
                    vendor: result.getText('entity'),
                    date: result.getValue('trandate'),
                    amount: result.getValue('amount'),
                    status: result.getText('status')
                });
                return true;
            });

            context.response.setHeader({ name: 'Content-Type', value: 'application/json' });
            context.response.write({ output: JSON.stringify(results, null, 2) });
        }
    };

    return { onRequest };
});
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?