I was wondering if anyone has had any success with...
# suitescript
j
I was wondering if anyone has had any success with creating suitelets accessible w/o login. Im trying to create one where it requires users to enter items on a sublist, but when I try to source items, it doesn't populate with anything, and I assume its a permission issue with the external role, online user form. Is there another way to handle this, or should I just have users need to log in? I was planning on handling authorization myself.
e
@Jordan I have run into this myself, and I don’t think i ever found a solution… hopefully someone else can chime in, maybe that will jog my memory
a
code? error message? give us a clue at least. I've used external suitelets plenty
j
Theres no error message. When I click the suitelet URL it shows a list of items, and when I click the external URL it shows nothing.
Copy code
function renderForm() {
        let form = sw.createForm({title: 'Ecommerce Portal', hideNavBar: true});
        let radioGroup = form.addFieldGroup({id: 'ordertype', label: 'Order Type'});
        let sampleOrder = form.addField({id: 'custpage_allowance', label: 'Sample Order', type: sw.FieldType.RADIO, source: 'sample', container: 'ordertype'});
        let allowance = form.addField({id: 'custpage_allowance', label: 'Use Allowance', type: sw.FieldType.RADIO, source: 'allowance', container: 'ordertype'});
        sampleOrder.defaultValue = 'sample';
        let sublist = form.addSublist({id: 'custpage_items', label: 'Ecomm Items', type: sw.SublistType.INLINEEDITOR});
        let itemField = sublist.addField({id: 'custpage_item_id', label: 'Item', type: sw.FieldType.SELECT, source: 'item'});
        // itemField.addSelectOption({value: '', text: ''});

        // let itemSearch = search.create({
        //     type: search.Type.ASSEMBLY_ITEM,
        //     filters: [['isinactive', 'is', 'F']],
        //     columns: ['internalid', 'displayname']
        // }).run().each(function(item) {
        //     let itemId = item.getValue({name: 'internalid'});
        //     let dn = item.getValue({name: 'displayname'});
        //     log.debug("itemId and display", itemId + ' | ' + dn)
        //     itemField.addSelectOption({value: itemId, text: dn});
        //     return true;
        // })
        sublist.addField({id: 'custpage_item_qty', label: 'Quantity', type: sw.FieldType.FLOAT});

        form.addSubmitButton({label: 'Create Order'});
        return form;
    }
a
idk what to tell you man, it works 🙂
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(['N/ui/serverWidget', 'N/search', 'N/record', 'N/redirect', 'N/runtime', 'N/log', 'N/url'], (
	serverWidget,
	search,
	record,
	redirect,
	runtime,
	log,
	url
) => {
	const onRequest = (context) => {
		try {
			if (context.request.method === 'GET') {
				let form = renderForm();
				context.response.writePage(form);

			} else {
				//handle POST
			}
		} catch (e) {
			log.error('Unexpected Error', e);
			context.response.write('An error occurred: ' + e.message);
		}
	};

function renderForm() {
        let form = serverWidget.createForm({title: 'Ecommerce Portal', hideNavBar: true});
        let radioGroup = form.addFieldGroup({id: 'ordertype', label: 'Order Type'});
        let sampleOrder = form.addField({id: 'custpage_allowance', label: 'Sample Order', type: serverWidget.FieldType.RADIO, source: 'sample', container: 'ordertype'});
        let allowance = form.addField({id: 'custpage_allowance', label: 'Use Allowance', type: serverWidget.FieldType.RADIO, source: 'allowance', container: 'ordertype'});
        sampleOrder.defaultValue = 'sample';
        let sublist = form.addSublist({id: 'custpage_items', label: 'Ecomm Items', type: serverWidget.SublistType.INLINEEDITOR});
        let itemField = sublist.addField({id: 'custpage_item_id', label: 'Item', type: serverWidget.FieldType.SELECT, source: 'item'});
        // itemField.addSelectOption({value: '', text: ''});

        // let itemSearch = search.create({
        //     type: search.Type.ASSEMBLY_ITEM,
        //     filters: [['isinactive', 'is', 'F']],
        //     columns: ['internalid', 'displayname']
        // }).run().each(function(item) {
        //     let itemId = item.getValue({name: 'internalid'});
        //     let dn = item.getValue({name: 'displayname'});
        //     log.debug("itemId and display", itemId + ' | ' + dn)
        //     itemField.addSelectOption({value: itemId, text: dn});
        //     return true;
        // })
        sublist.addField({id: 'custpage_item_qty', label: 'Quantity', type: serverWidget.FieldType.FLOAT});

        form.addSubmitButton({label: 'Create Order'});
        return form;
    }
	
	return{
		onRequest
	};
});
I'm guessing its an issue with the script deployment record...
image.png
proof it works as-is
to have that online form user show up you have to have this feature enabled, so that might your issue too...
j
I feel kind of silly for not trying to execute as admin, but that solved the problem, I had another role that had a lot of access but not admin access, do you know if theres a specific permission that role would need?
a
umm to show a list of items... umm item read I would guess? 😄 idk not a permissions expert tbh
j
The role I had it under before has item permissions, I thought there might be an additional permission that admin has that the role I was using didn't like something with online forms. This works though, thanks for your help
👍 1
n
I think external Suitelets work best with Execute As admin.
a
Also make sure the script deployment runs for the Online Forms role or a custom role based on that.
💯 1