Search code examples
netsuitesuitecommerce

SuiteScript Service get Database Info when User Not Logged In?


Can a SuiteScript Service grab information from the NetSuite database and return it as JSON to a user who is not logged into the website/NetSuite?

For example; if a user accesses http://website.com/sca-dev-montblanc/services/upcomingCourses.Service.ss the service should grab a list of upcoming courses from the NetSuite database and send it back as JSON.

I have implemented a SCA module with 1 SuiteScript Service file that does this but when the user is not logged in I get the response:

{"errorStatusCode":"403","errorCode":"ERR_INSUFFICIENT_PERMISSIONS","errorMessage":"Insufficient permissions"}

I have determined that the problem results from the nlapiLoadRecord('customrecord_course', 1); line in my service. When I comment this out and just send back dummy JSON everything works. So looks like a database access permissions problem. Is there anyway to allow access to this info without having the user logged in? Maybe I can change table permissions? Or if I make the service part of another application? Any advice would be extremely helpful.

    /*exported service*/
function service (request)
{
    'use strict';

    var Application = require('Application');

    try
    {
        var method = request.getMethod();


        switch (method)
        {
            case 'GET':

                // Below line of code causes error 
                var firstCource = nlapiLoadRecord('customrecord_course', 1);

                var coursesTest = [
                    {
                        course_id: record.getFieldValue('id'),
                        course_name: record.getFieldValue('name')
                    }
                ];

                Application.sendContent(coursesTest);
            break;

            default:
                Application.sendError(methodNotAllowedError);
        }

    }
    catch (e)
    {
        Application.sendError(e);
    }
}

Solution

  • Yes.

    In your script deployment mark the script as available without login and select all roles for the audience.

    In this instance you would generally use the external url for accessing the suitelet.