Error retrieving data from SuiteScript RESTlet due to an empty JSON string

I encountered a problem while trying to use the POST Function. I am attempting to convert a Transfer Order to an Item Receipt, but when running the script, it failed with the error message "org.mozilla.javascript.EcmaError: SyntaxError: Empty JSON string (INVOCATION_WRAPPER$sys#24".

Could someone assist me with resolving this issue?

Below is the Suitescript Code that I am using:

    function postData (receiptItem) {
    doValidation([receiptItem.recordtype], ['recordtype'], 'POST');

        if (receiptItem.recordtype == 'transferorder') {

            var recordId = [];
            var recStr = [];

                var objRecord = record.transform({
                        fromType: record.Type.TRANSFER_ORDER,
                        fromId: 131,             
                        toType: record.Type.ITEM_RECEIPT,
                        defaultValues: {
                        customform: '433'}
                    });

                    var itemReceiptId = objRecord.save({
                                enableSourcing: false,
                                ignoreMandatoryField: false
                        });

                    recordId.push(itemReceiptId)    

                    log.debug({
                        "title": "[success] recordId: ",
                        "details": recordId
                    });

                    var recLoad = record.load({
                            type: receiptItem.recordtype,
                            id: recordId.getValue('internalid')
                    });

                    recStr.push({
                        use_form: recLoad.getText('customform'),
                        tran_id: recLoad.getValue('tranid'),
                        tran_date: recLoad.getValue('trandate'),
                        tran_from: recLoad.getValue('transferlocation'),
                        tran_to: recLoad.getValue('location'),
                        tran_ord_id: recLoad.getvalue('createdfrom'),
                        tran_memo: recLoad.getValue('memo')
                    });

                    log.debug({
                        "title": "recStr",
                        "details": recStr
                    });

                return recStr;
        }
}
    return {
        post: postData
    };
});

Answer №1

There appears to be a syntax error in the code, possibly caused by a misplaced bracket.

Answer №2

Ensure that the JSON you are posting is valid and that your request has the correct content type set

Answer №3

Ensure that when sending data, it is in JSON format. If there is no data to send, include an empty object {} in the POST request with ContentType set as Application/JSON according to ECMA Standards. The error message will indicate "Empty JSON string".

You can test this using the Postman tool.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve the difference in time from the current moment using moment.js

I am trying to implement a functionality where I can track when my data was last updated. - After hitting the 'Update' button, it should display 'Update now' - If it has been n minutes since the update, it should show 'n mins ago& ...

Problems encountered while deciphering characters in API response

Struggling to manage values obtained from an external API service using Node. http.get( endpoint, function(res) { if (res.statusCode != 200) { return next(); } var pageData = ''; re ...

Header reference differs from the document referrer

this is the request header: GET / HTTP/1.1 Host: localhost:3002 Connection: keep-alive sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96" sec-ch-ua-mobile: ?0 User-Agent: ...

What is the best way to link a generated PHP-AJAX link with a jQuery action?

Imagine a scenario like this: trollindex.htm: [...] <script> $(document).ready(function(){ $("* a.jquery").on("click",function(){ $.ajax({ type: "POST", url: "trollcommander.php", data: ({comman ...

Retrieving JSON data from a form in a Node.js application

Situation : Here is the HTML code I am working with <form action="http://example.com/nodejs/endpoint" method="post" enctype="multipart/form-data"> <label> Select JSON file <input type="file" name="json"> ...

Troubleshooting: Datepicker not appearing in Bootstrap

Here is the detailed markup for the datepicker component: <div class="form-group row"> <div class="col-xs-3 col-md-offset-9"> <label class="control-label">Pick Date</label> <div class="input-group date" id="dp3" data-d ...

Error occurs when attempting to read the 'map' properties of null because the JSON array is double nested

Within my code, I am attempting to access the URLs of two thumbnails in the JSON data below. Currently, I can only retrieve the information from the first array: <>{post.attributes.description}</> However, I am encountering difficulty retrievi ...

What steps are necessary to utilize the Ajax Get method for accessing a WCF service? Is it essential to enable CORS?

I encountered a problem with Ajax connecting to WCF Service. We have been using Get and Post methods to retrieve JSON results. Despite following the standard coding on our website, we have tried numerous solutions to resolve this issue without success. The ...

What are some strategies to enhance the performance of JavaScript pagination to ensure it functions effectively for varying numbers of pages?

Currently, I am working on building Vanilla Javascript Pagination. I encountered an issue where the pagination seems to work flawlessly only when there are precisely 7 pages. If the page count exceeds or falls below 7, some minor bugs start to surface. I h ...

What is the best way to add elements to an array that has not been globally initialized as an empty array?

Let's say I have a variable called, let Info and an array like this one, let arr1 = [4,5,6] I need to add the elements from arr1 into Info as an array, Here is what I attempted, for(let i =0;i<arr1.length;i++){ Info = [] Info = Info.push ...

The page comes to a standstill while trying to read through a hefty JSON

Is there a way to improve the user interface when loading an 8MB json file using JSON.parse in Javascript? The page freezes for about 1-2 minutes, so I'm wondering if it's possible to parse async and display a loading or percentage info. I came ...

add element into the center of the div

I am attempting to insert an element (such as a div) in the middle of another div and directly after two line breaks. Below is an example of my code. The length of the div may vary. <html> <head> <title></title> <script ...

Jquery onchange event fails to fire

$('#selectclassid').trigger("change"); $('#selectclassid').on('change', function() { }); When trying to manually trigger the onchange event, it does not seem to be firing as expected. Although this format is commonly seen ...

Manipulate classes based on scrolling (Wordpress)

Trying to manipulate a widget by adding and removing classes based on user scroll behavior has proven to be quite challenging. Specifically, I aim to add one class when the user scrolls down by 50px and remove it when they scroll back up. Website: Check o ...

Displaying a single result in Angular from JSON without using the ng-repeat filter

Currently, I am working on developing an app to display news updates from a JSON API. The issue I am facing is that loading all the data from the JSON and filtering it using ng-repeat is causing slow performance, as there is a large amount of data. I woul ...

The issue of banding caused by Bloom and Antialiasing in Three.js rendering

I'm attempting to incorporate a glowing effect into my scene. To achieve this, I understand that using a bloom filter with the EffectComposer is the ideal approach. However, I've encountered an issue where utilizing the EffectComposer compromises ...

Issue with JSON conversion to List<SampleItem> in Spring Batch

When running my Spring Batch job, the initial step involves fetching JSON data from a REST service and storing it in a local HSQL table for future processing. After calling RestTemplate.exchange(), the JSON is retrieved as expected and converted into List ...

Concerns with "redirecting links script"

Check out this code snippet: <script> if(document.location.href.indexOf('https://customdomain.com/collections/all?sort_by=best-selling') > -1) { document.location.href = 'https://customdomain.com/pages/bestsellers'; } </sc ...

Decoding JSON with Single Quotes in Swift

Encountering an issue parsing JSON that contains single quotes. Utilizing JSONDecoder for this operation. The API response is provided below and I am seeking a workaround without the need for replacing or regex operations. Any suggestions? "{\&ap ...

Change the position of an array element when displayed on an HTML page

I'm trying to figure out a way to manipulate the position of an HTML element that is stored inside an array. The issue I am facing is that my code generates a new div every time a specific function is called, and this div has a class applied to it for ...