Hi, I'm creating a suitelet for the user to enter ...
# suitescript
p
Hi, I'm creating a suitelet for the user to enter some secured information so i was thinking of using
form.addCredentialField id: secrete_info
as i don't want it stored anywhere in NetSuite. However, in the post request, when i called the variable
id: secrete_info
to pass it in the body of a https.post, it either comes blank or comes up with some random number (probably encoded)
Copy code
form.addCredentialField({
                    id: 'secured_info',
                    label: ' Secure Info',
                    restrictToDomains: ['xxxx-aws.com','XXXXXXX.app.netsuite.com'],
                    restrictToScriptIds: 'customscript_share_secret_note',
                    restrictToCurrentUser: false
                }).maxLength = 19;
in my post section: below i would get some random numbers
Copy code
{
'secretNote': context.request.parameters.secured_info
}
below i just get "blank value".
Copy code
let secretNote = https.createSecureString({
                input: context.request.parameters.secured_info
            });

{
'secretNote': secretNote
}
b
number sounds weird, it should be a guid
you will want to pay closer attention to the N/https Module Script Samples
if you are trying to skip the secure string, then you need to pay closer attention to the credential paraemter of https.request
in general, working with credentials with N/https requires understanding what template processing is
p
yes it was GUID that was returned, but when i did as you mentioned adding the credentials parameter. it still shows the GUID information vs the actual secret message =/ i even tried doing securestring instead, but it did't work. if set securestring its blank.
b
what does your code look like
p
Copy code
function onRequest(context) {
            if (context.request.method === 'GET') {
                // Create a New Form for Entry/View
                let form = serverWidget.createForm({
                    title: 'Enter Secret Note',
                    hideNavBar: true
                });

                // Add the submit button
                form.addSubmitButton({
                    label: 'Submit'
                });

                let secretNote = form.addCredentialField({
                    id: 'secret',
                    label: ' Secret Note',
                    restrictToDomains: ['xxxxx.app.netsuite.com'],
                    restrictToScriptIds: 'customscript_cu_secret',
                    restrictToCurrentUser: false
                });

                context.response.writePage(form);
            }
            else if (context.request.method === 'POST') {
                let bodyJSON;
                let date = new Date();

                let secret = context.request.parameters.secret;
                
                bodyJSON['secreteMessage'] = {
                    'secretNote': context.request.parameters.secret,
                    'Date': date
                };
              
                let response = https.post({
                    credentials: [secret],
                    url: '<https://some-url.com/storesecretnote>',
                    body: JSON.stringify(bodyJSON),
                    headers: {
                        'accept': 'application/json',
                        'Authorization': 'Bearer ' + getToken(),
                        'Content-Type': 'application/json'
                    }
                });
            }
        }
b
you arent using it as a template
go learn how Advanced PDF/HTML Templates work if you want to learn the template engine netsuite uses
else learn a javascript template engine like https://handlebarsjs.com/
then come back to the request body you are generating once you learn what an expression is
p
thanks i'll take a look more i quite don't follow, but if you are saying template, does that mean i can't addCredentialField here to have it pass immediate, but i need to actually store it in the api secrets or generate/store/save it and then I can use it, as here i'm just grabbing the value immediately which isn't a template/expression?
b
api secrets and the guids function the same, they are identifiers that the template engine used by N/https will replace with actual values
ty1 1
that replacement only happens in expressions
your request body doesnt have expressions, hence no replacement