update customer custom fields from SCA or SSP - netsuite

I'm trying to update a custom entity field during registration in an SCA app.
the published Netsuite docs indicate I should be able to call:
var webStore = session.getSiteSettings(['displayname', 'id']);
customer = session.getCustomer();
customer.updateProfile({
internalid: internalid,
customfields: {
custentity_registered_site: webstore.id
}
});
but this throws the ever helpful UNEXPECTED_ERROR
Has anyone had this working for custom fields? I am doing this just after registration so that may be the issue though I can get a valid customer internalid. Any luck with alternate syntax of some sort?

Eventually was able to get NS support to give me their internal stack trace.
The issue has to do with some internals from the Rhino Javascript engine that NS uses.
Basically the value returned from the NS API was returning a string like value and NS was not following the 2014 recommendation on its use and was failing in the underlying Java code. So the fix was simple but so frustrating:
var webStore = session.getSiteSettings(['displayname', 'id']);
customer = session.getCustomer();
customer.updateProfile({
internalid: internalid,
customfields: {
custentity_registered_site: webstore.id.toString()
}
});
Hope this helps someone.

Related

INVALID_RECORD_TYPE when voiding CHECK in Netsuite using Suitescript 2.0?

I'm trying to void transactions via script. It's working for all the other transactions except for check record and I can't figure out why. I'm getting the INVALID_RECORD_TYPE error.
Here's a sample code I am using.
var id = transaction.void({
type: 'check',
id: 25
});
Thanks.
Please check Setup > Accounting > Accounting Preferences > General: VOID TRANSACTIONS USING REVERSING JOURNALS.
If the preference is not checked, the Void button does not appear in checks and you get the invalid record type error.
Please check the Field Level help of the preference for details. You will need to toggle the preference (using N/config) before calling transaction.void on types that are not covered by your account setting.
You must Reversing Journal
and then this:
var checkId= transaction.void({
type: transaction.Type.CHECK,
id: 25
});

Stripe: Getting Credit Card's Last 4 Digits

I have upgraded the Stripe.net to the latest version which is 20.3.0 and now I don't seem to find the .Last4 for the credit card. I had the following method:
public void CreateLocalCustomer(Stripe.Customer stipeCustomer)
{
var newCustomer = new Data.Models.Customer
{
Email = stipeCustomer.Email,
StripeCustomerId = stipeCustomer.Id,
CardLast4 = stipeCustomer.Sources.Data[0].Card.Last4
};
_dbService.Add(newCustomer);
_dbService.Save();
}
But now the stipeCustomer.Sources.Data[0].Card.Last4 says 'IPaymentSource' does not contain a definition for 'Card'. Does anyone know how I can get the card details now? The flow is that I create the customer by passing the Stripe token to Stripe, then I get the above stripeCustomer. So I expect it to be somewhere in that object. But I can't find it. The release notes can be found here.
Thank you.
In the old world of Stripe, there only used to be one type of payment method you could attach to a Customer; specifically, Card-objects. You would create a Card-object by using Stripe.js/v2 or the Create Token API Endpoint to first create a Token-object and then attach that token to a Customer-object with the Create Card API Endpoint.
Once Stripe expanded to support a number of other payment methods though, Stripe built support for a new object type that encapsulated a number of payment methods (including credit cards) called Source-objects. A Source-object is created either by using Stripe.js/v3 or the Create Source API Endpoint. It can also be attached to a Customer-object in much the same way as the Card-objects mentioned above, except they retain their object type. They're still a Source. You use the Attach Source API Endpoint to do this (that is notably identical to the Create Card API Endpoint mentioned above).
What I'm getting at here, is there are now two different object types (or more) that you can expect to see returned in the sources-array (or Sources in .NET). All of these methods though inherit from the IPaymentSource-interface. So if you know you have a Card-object getting returned, you can simply cast the returned object to the Card-class.
Something like this should get you going:
CardLast4 = ((Card) stipeCustomer.Sources.Data[0]).Last4
You can see what I mean by inheritance by looking at this line in the Card-class file:
https://github.com/stripe/stripe-dotnet/blob/master/src/Stripe.net/Entities/Cards/Card.cs#L7
Good luck!
As of Stripe.net.21.4.1, this is what works:
var chargeService = new ChargeService();
var charge = chargeService.Get(id);
CardLast4 = ((Card)charge.Source).Last4;
It's getting hard not to panic when code breaks because of all the micro-changes Stripe makes.
So after debugging, it looks like the Data[0] needs to be cast as Card to get the card.
So it will be CardLast4 = ((Card)stipeCustomer.Sources.Data[0]).Last4.

How to find all documents in couchDB using ektrop library

I have gone through all the blogs available for the ektrop library and also the source code of the library.I have found that get(class obj,String id) function is available but If I use this function then only one document will be returned according to the id given.So I want to read all the changed documents present in the bucket.How Can I achieve this.Thanks in advance any help would be appreciable.
You are probably looking for the _all_docs endpoint.
ViewQuery q = new ViewQuery().allDocs().includeDocs(true);
List<Sofa> bulkLoaded = db.queryView(q, Sofa.class);
You can find more detailed information in the api
Hello all I have got the answer the question asked by me above.Here is the steps by which you can get the all documents or simply the result of _changes API is used.
Integrate the Ektorp library into your project.
Use the follwing code to get the all document.
HttpClient httpClient = new StdHttpClient.Builder()
.url("http://localhost:5984/")
.build();
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
CouchDbConnector db = new StdCouchDbConnector("my_database", dbInstance);
ChangesCommand.Builder builder = new ChangesCommand.Builder();
ChangesCommand changesCommand =builder.build() ;
List<DocumentChange> documentChangeList=db.changes(changesCommand);
for(int i=0;i<documentChangeList.size()-1;i++) {
System.out.println(documentChangeList.get(i).getId());
}

Netsuite bug when creating customerdeposit record

Im trying to create a customer deposit record in Netsuite using suitescript 1.0.
The original code I had in place which had been working perfectly up until the 2016.2 release broke it.
The update broke it, in that it would override the value submitted in the payment field and instantly make it the full amount of the sales order from the sales order ID. Which is not what we need it to do.
Original Code
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit');
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
After a reply on the Netsuite user group prompted me to use the {recordmode:'dynamic'} attributes I am getting a strange error..
Test Replacement Function which doesnt work
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit',{recordmode:'dynamic'});
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
The error message Im getting now is
Invalid salesorder reference key 1260 for customer .
The thing I dont get is how it is now considered NULL, when the value is hardcoded into this test script after I apply the {recordmode:'dynamic'} value.
Ive tried a wide variety of things, but as I dont have Netsuite support, its proving to be something I simply cant figure out.
Any hints, suggestions would be greatly appreciated as Ive been on this for several days
When you use dynamic the order you set fields makes a difference. So when you set the sales order prior to setting the customer you are actually getting the error message "Invalid salesorder reference key 1260 for customer blank"
What I do is create the customer deposit like:
var depRec = nlapiCreateRecord('customerdeposit', {entity:soRec.getFieldValue('entity'), salesorder:soId});
also setting the undeposited funds flag seems to be required (but not always for some reason) so since you are supplying an account id also do this:
depRec.setFieldValue('undepfunds', 'F');

Using the Spotify iOS SDK, how can I tell what market the user is connected to?

Is it possible to tell the country associated with the current user's account with the iOS Spotify SDK? How? I have not been able to find anything in the docs.
(I'd like to get the ISO 3166-1 alpha-2 country code so that another (unauthenticated) user can do searches with the web api and only find tracks that we will ultimately be able to play using the authenticated user that is using the SDK.)
Found it. It is available from the territory field of the SPTUser object. Here is how you might get it after having logged in and received a session object, example code in Swift:
SPTUser.requestCurrentUserWithAccessToken(session.accessToken) { error, object in
guard let user = object as? SPTUser,
territory = user.territory else {
print("Could not get territory, error: \(error)"
return
}
print(territory)
}
However, you will get nil values for the territory unless you have included SPTAuthUserReadPrivateScope in requestedScopes when setting up your SPTAuth object.

Resources