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.

How to solve : "Bad control character in string literal in JSON" ?

User205031
Tera Contributor

Hi All,

 

I am trying to pass rejection comments through JSON once the RITM state is rejected.

The JSON payload is :

User205031_0-1762238681792.png

But I am getting the below error in the response body:

 

User205031_1-1762238714559.png

 

How can I solve this issue?

Thanks in advance!

10 REPLIES 10

@User205031 

another way is to get only the text from the comments by querying sys_journal_field table

(function execute(inputs, outputs) {
    // ... code ...

    var ritmNo = inputs.ritm_no.sys_id;
    var stateValue = inputs.state;

    var grApproval = new GlideRecord('sysapproval_approver');
    grApproval.addQuery('document_id', ritmNo);
    grApproval.addQuery('state', stateValue); // Filter for rejected approvals
    grApproval.orderByDesc('sys_created_on'); // Get the most recent rejection
    grApproval.query();
    var rejectionComments = '';
    if (grApproval.next()) {
        var rec = new GlideRecord('sys_journal_field');
        rec.orderByDesc('sys_created_on');
        rec.addQuery('name', 'sysapproval_approver');
        rec.addQuery('element', 'comments');
        rec.addQuery('element_id', grApproval.sys_id);
        rec.setLimit(1);
        rec.query();
        if (rec.next()) {
            rejectionComments = rec.getValue('value');
        }
    }
    // Output the rejection comments for use in subsequent flow steps
    outputs.comment = rejectionComments;

})(inputs, outputs);

💡 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

@User205031 

Hope you are doing good.

Did my reply answer your question?

💡 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

Hi @Ankur Bawiskar ,

 

After using JSON.stringify(rejectionComments) it worked. Also, while passing comment through Request body, I have removed the "".

It is working now.

Thanks!

@User205031 

JSON.stringify you were already using and it didn't work

You can use either of the 2 approaches I shared

1) use directly as below

outputs.comment = rejectionComments;

OR

2) query sys_journal_field and get the value

💡 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

Hi @Ankur Bawiskar ,

 

I will try these 2 approaches.

 

Thanks!