Error ” UNSUPPORTED_DATA_FORMAT ” when passing the data to render an Advanced PDF template

The error message was as follows:

{“type”:”error.SuiteScriptError”,”name”:”UNSUPPORTED_DATA_FORMAT”,”message”:”You have supplied an invalid value for data format: JSON: Element type “Home” must be followed by either attribute specifications, “>” or “/>”.”,”id”:””,”stack”:[“Errorn at initiatePrint (/SuiteScripts/Jobin and Jismi IT Solutions/DVTB-341/jj_sl_render_template_dvtb343.js:94:27)n at Object.onRequest (/SuiteScripts/Jobin and Jismi IT Solutions/DVTB-341/jj_sl_render_template_dvtb343.js:43:40)”],”cause”:{“type”:”internal error”,”code”:”UNSUPPORTED_DATA_FORMAT”,”details”:”You have supplied an invalid value for data format: JSON: Element type “Home” must be followed by either attribute specifications, “>” or “/>”.”,”userEvent”:null,”stackTrace”:[“Errorn at initiatePrint (/SuiteScripts/Jobin and Jismi IT Solutions/DVTB-341/jj_sl_render_template_dvtb343.js:94:27)n at Object.onRequest (/SuiteScripts/Jobin and Jismi IT Solutions/DVTB-341/jj_sl_render_template_dvtb343.js:43:40)”],”notifyOff”:false},”notifyOff”:false,”userFacing”:true}

It was showing when the key of the object which was passing has the symbol ‘&’ in it. It also throws error when the key has space in between them. The special symbols should be replaced in order to successfully pass the data to the pdf. For that, the data can be passed into the following function:

function escapeXml(unsafe) {
            try {
                if (unsafe) {
                    return unsafe.replace(/[<>&'"]|- None -/g, function (c) {
                        switch (c) {
                            case '<':
                                return '&lt;';
                            case '>':
                                return '&gt;';
                            case '&':
                                return '&amp;';
                            case ''':
                                return '&apos;';
                            case '"':
                                return '&quot;';
                            case '- None -':
                                return 'Nil';
                            default:
                                return c;
                        }
                    });
                }
            }
            catch (e) {


                return log.error("error@unsafe", e.message);
            }
        }

Leave a comment

Your email address will not be published. Required fields are marked *