When using form.addCredentialField(options) , how ...
# ask-stanley-ai
e
When using form.addCredentialField(options) , how do I read the credential at a later stage? In SuiteScript 2.1
c
AI generated answer (using internal Slack threads):
In SuiteScript 2.1, you can use the
form.addCredentialField
method to add a credential field to a form. This method returns a GUID that you can use later to retrieve the stored credentials. Here's a general process for creating credential fields and then, later, getting their handles and passing them on using `nlapiRequestURLWithCredentials`: 1. Add two custom fields with username and passwords to a form:
Copy code
javascript
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 two custom fields, which are not visible on the form:
Copy code
javascript
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 the domain that the credentials will eventually be sent to. NetSuite will only send the credentials to the chosen domain. Once you enter a value into the credential field, it will be replaced with a GUID. You can then use this GUID in your requests to a third-party endpoint. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.817518532
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.815468907
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.811074138
Please provide your feedback on this answer.