why is this suitelet giving me privileges' error i...
# suitescript
l
why is this suitelet giving me privileges' error its set to be available without login.
a
its probably related to whatever the suitelet is trying to display? which you haven't mentioned at all?!
l
three custom fields on a contact record. the suitelet is supposed to update those fields depending on user's selection
a
if you're asking if you setup the script for available with login... then yes, it appears you have set that up correctly
l
yes i have no issue accessing the script , and the suitelet works great. its just the external link that doesnt work .
a
we need the suitelet code... something in the suitelet code is expecting a user session of some kind is my guess... and you don't have a user session, or not a real one, so it can't use info it doesn't have and returns an error
but without sharing code I'm just guessing
l
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/ui/serverWidget', 'N/record', 'N/redirect', 'N/search', 'N/runtime'], 
function(serverWidget, record, redirect, search, runtime) {

    function onRequest(context) {
        if (context.request.method === 'GET') {
            var form = serverWidget.createForm({ title: 'Email Preferences' });

            // Adding field group
            form.addFieldGroup({
                id: 'main_info',
                label: 'Main Information'
            });

            form.addFieldGroup({
                id: 'preferences',
                label: 'Preferences'
            });

            // Email field
            var emailField = form.addField({
                id: 'custpage_email',
                type: serverWidget.FieldType.EMAIL,
                label: 'Email Address',
                container: 'main_info'
            });
            emailField.isMandatory = true;

            // Preferred Manufacturers field
            var manufacturerField = form.addField({
                id: 'custpage_preferred_manufacturer',
                type: serverWidget.FieldType.MULTISELECT,
                label: 'Preferred Manufacturers',
                source: 'customlist1', // custom list id
                container: 'preferences'
            });
            manufacturerField.isMandatory = true;

            // Email Frequency field
            var frequencyField = form.addField({
                id: 'custpage_email_frequency',
                type: serverWidget.FieldType.SELECT,
                label: 'Email Frequency',
                source: 'customlist_daily_inventory_list_option', // custom list id
                container: 'preferences'
            });
            frequencyField.isMandatory = true;

            form.addSubmitButton({ label: 'Submit' });

            context.response.writePage(form);

        } else {
            var email = context.request.parameters.custpage_email;
            var preferredManufacturers = context.request.parameters.custpage_preferred_manufacturer;
            var emailFrequency = context.request.parameters.custpage_email_frequency;

            // Parse the preferred manufacturers into an array
            var preferredManufacturersArray = preferredManufacturers ? preferredManufacturers.split(',') : [];

            // Search for the contact with the given email address
            var contactSearch = search.create({
                type: search.Type.CONTACT,
                filters: [
                    ['email', <http://search.Operator.IS|search.Operator.IS>, email]
                ],
                columns: ['internalid']
            });

            var contactId;
            contactSearch.run().each(function(result) {
                contactId = result.getValue('internalid');
                return false; // Exit loop after finding the first match
            });

            if (contactId) {
                // Load and update the contact record
                var contactRecord = record.load({
                    type: record.Type.CONTACT,
                    id: contactId
                });

                contactRecord.setValue({
                    fieldId: 'custentity_preferred_manufacturer_email',
                    value: preferredManufacturersArray
                });

                contactRecord.setValue({
                    fieldId: 'custentity_daily_inventory_list_email',
                    value: emailFrequency
                });

                contactRecord.save();

                context.response.write('Preferences updated successfully.');
            } else {
                context.response.write('No contact found with the provided email address.');
            }
        }
    }

    return {
        onRequest: onRequest
    };
});
is it the fact that its performing a search?
a
is it failing without login on the GET or the POST?
cos it isn't doing a search in the GET
l
its failing as soon as i load the page
a
k so you're doing any searches in the GET path, so no its not cos of the search
l
thats what i thought. so no idea what it is
a
yeah, so I'm not seeing anything suspect in your GET code
try removing redirect and runtime modules? you're not using them anyway, I'm thinking maybe redirect could be abused potentially and so NS just error out external suitelets if its used? that's wild speculation on my part but there's not much of anything else in your code that could be a problem
the other thing you can do is just return some raw HTML instead of your code, just to test if that works
Copy code
if GET
return "<html><head></head><body><p>hello world</p></body></html>"
or something? idk if it needs to be a string, been a while
if the raw html response is ok then its something in your NS code if the raw html also fails... then its a something config related in the account/objects
l
good idea let me try that
still same thing
e
Did you check the "Audience" sub tab and enable "all roles" ?
l
a
yeah its something like that though, has to be
wait, why is there somethign in the subsidiary field?
l
cause we have three subsidiaries
a
pretty sure its going to compare the user session settings for subsidiar against that... and you dont HAVE user session settings
l
how do i fix this?
a
just remove the subsid restriction and leave it empty
l
oh man.. that did it
🙌 1
thanks a lot
a
if you posted the first deployment screen shot as the full screen shot instead of clipping it that would have stuck out right away
l
crap. didnt know that would make a difference.
a
its ALWAYS the thing that you dont think makes a difference in these cases..... 😄
l
LOL i know, i hate this
😂 1
thanks again
👍 1
150 Views