Accessing Address fields in Suitescript on Transaction level - netsuite

In 2014.2 Netsuite changed it's structure of addresses making them subrecords. They have a lot of help around scripting addresses on the Customer level or Form level, however I need to on the transaction (quote, sales order, invoice) level.
Help for transaction level appears to be just this page: https://netsuite.custhelp.com/app/answers/detail/a_id/39551/kw/address
This however is creating a custom address which shows that custom billing and shipping addresses have their own internal id.
What is the internal ID that I can use on the nlapiViewSubrecord(fldName) call to get at the values of say country, state, zip, etc on the billing and/or shipping addresses? I have tried 'billaddress' and 'shipaddress' respectively with no luck.

Try billingaddress and shippingaddress. I've recently made a similar update to some of our Sales Order code, and this is what worked for me.
// {String} The type of address to create, will be one of ship or bill
var addressType = (type === 'ship' ? 'shippingaddress' : 'billingaddress');
// {nlobjSubrecord} Address subrecord object
var subrecord = order.createSubrecord(addressType);
(This is in a RESTlet; the type value here is something that gets sent to us)

Related

Search payment records information in Netsuite using Suitelet

Need to get payment data from Transaction >> Payable >> Pay single vendor form and create a data file. This has been done with an eventscript (add button), a clientscript and a Suitelet by searching currentRecord data from client script to Suitelet and generated a file. However, searching Transaction record type could not get payer payment department and cost center data as I know. So any advice and recommendation from Netsuite experts on how can get these payer data from Netsuite with the existing Transaction information on the Bill Payment form, like payment check number, entity id, transaction number, etc ?
When using the N/search module the following 3 tools are invaluable for retrieving data from netsuite transactions.
Netsuite records browser (shows all of the fields, available search filters, and joins ect.)
https://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2020_1/script/record/vendorpayment.html
Another great tool is an extension called Netsuite Field Explorer developed by Michoel Chaikin
you can also turn on field ids in your account by navigating to Home->Set preferences->General tab->Set defaults->Show internal ids
(This will show the field id when you click on the field "What is this?" link directly on the record)
between the three you should be able to get everything you need to run a search and retrieve the data you are looking for.
Depending on your needs you can either search.create (return multiple records) or search.lookupfield(return a single record)

Get Default Payment Source (default card) for Stripe Customer?

I created a POC with a customer/credit card in Stripe and I logged into my dashboard within Stripe and was able to see this customer has a default source (the test credit card I added) associated correctly. It shows this card is the default source.
When I run this .Net code:
var customerService = new CustomerService();
var stripeCustomer = await customerService.GetAsync(customerId);
To get that customer, it returns everything correctly except his source. All of the fields I had hoped I can find it from are empty! I want to know his default payment source so I can show it on the front end with a little icon to indicate it's default.
DefaultSource, DefaultSourceId, and Sources properties are all blank/null.
Is there a way to have Stripe return it, or do I need to do something else? I tried the 'expand' property for the GetAsync method but that threw an error saying the above properties are not expandable (i.e. I can't ask Stripe to expand/return Source).
Any ideas what I can do?
FYI I also tried this:
var paymentMethodService = new PaymentMethodService();
var cards = await paymentMethodService.ListAsync(new PaymentMethodListOptions { Customer = customerId, Type = "card"});
and there doesn't seem to be a property anywhere that says the card is default (although it does correctly return all cards). I believe Stripe documentation states the Customer is the holder of the default source, not the card object. What gives?
Thanks in advance!
It looks like you're using Payment Methods, since your payment method list call has the results you expect, which means the customer likely doesn't have any sources. You can try that again with the properly pluralized expand[]=sources if you do know your Customer has Sources attached.
For Payment Methods, there is no general default for the Customer. For one-time Payment Intents, you must always specify the payment_method from among those attached to the Customer for future payments.
For paying invoices (related to recurring subscriptions, eg), you can set the invoice_settings.default_payment_method for Customer. This only applies to invoices.

NetSuite: how to get or set a value for an OtherCustomField through SuiteTalk SOAP API

In the NetSuite Customization UI, I've defined an "Other Custom Field" which applies to Address. I've edited a Customer's Address and specified a value for this custom field. When I use a SuiteTalk SOAP request to "get" this Customer, the response includes all of the customer's data, including all of the address fields, but there's nothing that corresponds to the custom field's value for this address. This makes some sense since there's no "customFieldList" field to reference custom field values on an Address, as there is on the Customer itself and many other types of records. So how can I get or set the value of an "otherCustomField" for a particular record that it applies to (a particular Address in this case)? I've searched the NetSuite documentation, the support knowledge base and the internet, and so far, no luck.
And, yes, I already know how to get the metadata for the custom field itself using getCustomizationId and get/getList. But I need data, not metadata.

Workaround to search Netsuite Note record by Customer id

I'm trying to get an app I'm working on to display all associated user notes for a given Customer record (as it appears on the UI Customer record page in Netsuite proper).
To that end, I've set up a Netsuite RESTlet to return a list of internal ids for associated Note records given a Customer internal id.
I've set up a simple search in the RESTlet script:
function get_notes(params) {
log("GET params", JSON.stringify(params));
var filters = [
new nlobjSearchFilter('internalid', 'customer', 'is', params.id)
];
var columns = [
new nlobjSearchColumn('internalid'),
new nlobjSearchColumn('note'),
];
var search = nlapiCreateSearch('note', filters, columns);
var notes = search.runSearch().getResults(0, 3);
return notes;
}
function log(msg, details) {
nlapiLogExecution('DEBUG', msg, details);
}
The script works as expected, but the problem is that this search ONLY returns Notes for which the author field (which is a user internal id) matches the internal id of the user performing the search. Meaning - you can only search for Notes for which you are the author.
I have been informed that this is a 'feature' of Netsuite for some unfathomable security reason.
I need to be able to get a list of all the associated Note ids, not just those for which the user making the request is the author.
Any ideas on a workaround to get at all the associated Notes? A different way to structure the search? Some kind of secret way to define your own custom Search Joins?
I can't even find documentation on this behavior (blocking Note searches from non-authors). Perhaps someone knows how to override it at the admin level?
I'm not quite ready to admit that this is impossible yet.
NB: User Note is a Note-type record associated with the Customer record, not a field on Customer record, so I can't access it directly from Customer. There is also not a Search Filter or Search Join for Note or User Note.
Using RESTlets you cannot get the notes of other users unless you invoke the RESTlet using credentials/tokens of roles like Administrator/Full Access. RESTlets always runs in the context of current user.
One alternative to do that, if you really got to achieve this any how:
1) Create a user event script on customer which creates a custom record that simulates the functionality of system notes.
2) Make sure that the RESTlet user roles have full level of access on the custom record and make customer as parent of your custom record.
3) In your RESTlet return the custom records.
Basically RESTLETS always run as the user who invokes them.
If you can use a Suitelet for this you can set that up to run as Administrator and can return any Notes you can craft a search for.
Are you actually needing a Restlet ? i.e. Are you calling this from an external application or are you trying to add functionality in the NS GUI? If the latter then you can easily use a Suitelet.

How to get customer billing address in blCheckoutWorkflow in broadleaf?

I would like to the get customer billing address details and would like to log them in an activity class in the blCheckoutWorkflow.
I have tried the following.
Order order=context.getOrder();
Customer c=order.getCustomer();
c.getCustomerPayments().get(0).getBillingAddress();
But here the size of the list returned by getCustomerPayments() is 0. So I am getting ArrayIndexOutOfBoundsException.
Is there a way to get the billing address that is entered by the customer in the /checkout.
Kindly, reply me.
getCustomerPayments() is designed to hold saved payment information for a particular Customer and is not really applicable to the current Order. This is used when a Customer wants to save payment information for checking out next time (the 'token' property on CustomerPaymentImpl is used to look up the PCI-sensitive data from the payment gateway).
If you are using Broadleaf 3.1.0-GA+ then you should do:
Order order = context.getOrder();
Address billingAddress = order.getOrderPayments().get(0).getBillingAddress();
If you are using Broadleaf 3.0.10-GA or below you should do:
Order order = context.getOrder();
Address billingAddress = order.getPaymentInfos().get(0).getAddress();

Resources