I'm calling a suitelet from an SS2 service file to...
# suitecommerce
s
I'm calling a suitelet from an SS2 service file to do some additional bts. The suitelet is expected to return json data but it appends some system generated html data to that json data which causes error while parsing. Doesn anyone know why html content gets appended even when content-type is set to json?
e
@Sohan Kumar Dash share your code or at least your return and how you are getting the returned value.
b
Because the response your getting is an unhandled error, look at the execution logs of your SSP for actual details of the error
👆 1
s
Here are the snapshots of the code blocks. 1. SS2 Service file. 2. Suitelet script 3. Response Preview on browser
@Bryce Krah I have implemented appropriate error handling logic in the service file and I don't see any execution log under the SSP application. The suitelet response is directly going to the SC website which shouldn't be happening.
e
@Sohan Kumar Dash I have not have the need to create a suitelet to be called from a 2.0 service, the behaviour is weird, is the deployment avialable without login? I would change
response.write
to
response.writePage.
and probably the headers are not needed.
b
I've only ever seen/done the whole SL response as a string while it looks like yours is an object where you stringify the message? I've also only used writePage when you return a NS form
In the console if you could show the response not the preview it would be more helpful
s
@eminero I agree, you might not be able to perform the following operations consecutively from an SS2 service file. 1. Create/Edit a customer record. 2. Attach some files to the above record. 3. Send an email to the customer. The service file only performs step 1 successfully but fails at step 2/step 3. Also, I wasn't able to perform the above 3 steps from a suitelet as well. That's why I chose to break down the above 3 steps into 2 parts. Step 1 will be done by the service which will then make a call to the suitelet that perform step 2 and 3 at once and respond back with a JSON
{"message": "ok"}
. The service file will parse the suitelet's response and will respond back to the SC website. But here the suitelet directly responds back to the SC website with (JSON + HTML) mixed data.
@eminero
is the deployment avialable without login?
Yes. I think
writePage
will render a page instead of sending JSON data.
@Bryce Krah Here is the snapshot of the response in raw format. FYI, I just want to send a JSON object in a suitelet response, not an HTML page.
e
Call your suitelet from a browser tab, I mean just click on the external URL, did you get just the message ok or the HTML content as well? You could create a model in 2.0 en elevate the permissions to attach documents and send emails.
s
Haven't tried the first part, will give it a try. The service file already has administrator-level permissions.