I’m running into some issues with the `form.addCr...
# suitescript
j
I’m running into some issues with the
form.addCredentialField
method for use with
nlapi.nlapiRequestURLWithCredentials
.
Details to come
From the documentation: The following shows a general process for creating credential fields and then, later, getting their handles and passing them on using
nlapiRequestURLWithCredential
1. Two custom fields with username and passwords are added to a form:
Copy code
var credField = form.addCredentialField('custpage_credname', 'password', null, valueFromCustomField, '<http://cert.merchante-solutions.com|cert.merchante-solutions.com>', 'customscript_usecredentialfield');
var usrfield = form.addCredentialField('custpage_username', 'username', null, valuefromusernamecustfield, '<http://cert.merchante-solutions.com|cert.merchante-solutions.com>', 'customscript_usecredentialfield')
2. During a beforeSubmit user event, obtain the values from credential fields and store them in twocustom fields, which are not visible on the form:
Copy code
var credValue = nlapiGetFieldValue('custpage_credname');var username = nlapiGetFieldValue('custpage_username');nlapiSetFieldValue('custentity_custompassword', credValue);nlapiSetFieldValue('custentity_customusername', username);
The domain field in `form.addCredentialField`… is that the domain that the form exists on, or is it the domain that the credentials will eventually be sent to?
b
domain that the credentials will eventually be sent to
its used so that NetSuite will only send the credentials to the chosen domain
j
Okay. I’m getting blank values when I’m logging them to my console, so I’m trying to see where in this process I’m missing something
b
what are you trying to log?
j
Sorry, I read “do” not log
I am trying to log the value of
nlapiGetFieldValue('custpage_credname')
on the vendor page
I expect to get some encrypted string
b
im assuming you set a value in your credential field
j
Yes, I guess I’ll put it on pastebin since threads don’t support code snippets
This https://pastebin.com/cpczSh2u is my User Event script
b
your credential field adding code looks fine, but for the weird label
which record is this deployed to
j
This https://pastebin.com/EWvafznn is my Client script applied to the Vendor record. When I save, the fields are showing empty strings. New behavior showing up, it says “Please enter value(s) for: billy, password123” on save in an alert
b
yea
you need to manually enter values into your credential fields
j
I did not realize that those were labels
b
once you enter a value into the credential field, it will be replaced with a guid
j
Okay, now I think I understand…
I thought the label field was the actual value of the credential field. I am not trying to collect credentials from the user. I am just trying to have credentials available to any request that I send to a third party endpoint so I can be notified of changes
b
this is a one time thing
you enter your credentials, get a guid, then use the guid afterwards
j
Per user or per deployment
I think this means that this is the wrong approach for my use case
b
unless you setup the credential field to do so, its per script
the part you are at is essentially saving the password in netsuite
you only do that once, unless you change passwords
j
Think I know what to do. 1 minute
Well, now I’m seeing
JS_EXCEPTION ReferenceError nlapiRequestURLWithCredentials is not defined
Because this is not supposed to be a client side script…
Should I be doing
nlapiRequestURLWithCredentials
in after submit user event?