Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

テンプレートを使用したPDFの出力について

Pirakawa
Tera Contributor

いつもお世話になっております。

 

ポータル画面でレコードを開いた時、UIアクションを押下すると設定したテンプレートでレコード内容がPDF化される機能を実装したいと考えております。

 

しかし、以下のコードを設定してもうまくいきませんでした。

(function executeAction(current) {
    // ドキュメントテンプレートの sys_id(事前に作成したテンプレート)
    var templateSysId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // ←テンプレートのsys_idを指定

    // 出力するファイル名
    var fileName = '契約書.pdf';

    // APIインスタンス生成
    var docGen = new sn_docGenerateDocumentAPI();

    // ドキュメント生成(対象レコードに添付)
    var result = docGen.generateDocumentForTask(current.sys_id, templateSysId, fileName);

    // 結果確認
    if (result) {
        gs.info('ドキュメント生成成功: ' + fileName);
    } else {
        gs.error('ドキュメント生成に失敗しました');
    }
})(current);

 

どのようにすればテンプレートでPDFが出力できるようになりますでしょうか。

1 件の受理された解決策

Ankur Bawiskar
Tera Patron
Tera Patron

@Pirakawa 

your code will work in UI action if it's server side and mapping etc is proper.

if you are planning to use Document templates then I assume your configuration is already there

check my blog on how to invoke that

Generating and Attaching Document Templates in ServiceNow to Record - Server Side 

are you getting any cross scope errors in log?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

元の投稿で解決策を見る

2件の返信2

Ankur Bawiskar
Tera Patron
Tera Patron

@Pirakawa 

your code will work in UI action if it's server side and mapping etc is proper.

if you are planning to use Document templates then I assume your configuration is already there

check my blog on how to invoke that

Generating and Attaching Document Templates in ServiceNow to Record - Server Side 

are you getting any cross scope errors in log?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar さん

ブログに掲載いただいていた内容で実装ができました!!!!ありがとうございました!!!!!!