Loading custom record in SuiteScript 2.0 - netsuite

I'm trying to load a custom record like below:
var mergeRecord = record.load({
type: record.Type.'custrecord_merge_vendor',
id: '12',
isDynamic: true
});
This seems wrong.. but the equivalent for standard records is like below:
var objRecord = record.load({
type: record.Type.SALES_ORDER,
id: 157,
isDynamic: true,
});
How to do this ?

Like this:
var mergeRecord = record.load({
type: 'custrecord_merge_vendor',
id: '12',
isDynamic: true
});

You have the right idea, except that you are not passing the correct record type for your Custom Record into the type property. The correct value will just be the string that is your Custom Record's internal ID; it will start with customrecord_. You will not use the record.Type enumeration as that is only for native record types.
Because something like record.Type.'custrecord_merge_vendor' is not even valid syntax, I highly suggest you familiarize yourself with the fundamentals of the JavaScript language. You can find tons of introductory information and examples over at MDN

Related

How to access Search Record and set some field?

I want to load a saved search , and set "inactive" field to true.
Problem is I tried to load it , but it failed
I tried this :
var searchRec = record.load({ type: search.Type.SAVED_SEARCH, id: result.id, isDynamic: false });
Also read the help on the N/search module but no answer.

Update Custom Address Field in Netsuite using SuiteScript 2.0

I created a new custom field in the 'US' address form called 'email', so I can have an email address associated with both the bill to and ship to on a sales order in Netsuite. I am trying to update this field using Suitescript 2.0, but cannot seem to save the changes. Can anyone give any insight?
var salesorder = record.load({
type: record.Type.SALES_ORDER,
isDynamic: true,
id: 6835
});
var shippingAddressSubrecord = salesorder.getSubrecord({fieldId : 'shippingaddress'});
var email = shippingAddressSubrecord.getValue({fieldId : 'custrecord_email_address' }); //returns correctly
shippingAddressSubrecord.setValue({fieldId : 'custrecord_email_address', value: 'test2#gmail.com', ignoreFieldChange: true });
var salesorderid = salesorder.save({enableSourcing: true, ignoreMandatoryFields: true});
This gives the error: "type":"error.SuiteScriptError","name":"OPERATION_IS_NOT_ALLOWED","message":"The subrecord line has already been committed or cancelled. The previous subrecord reference is no longer valid. You must get another reference to the subrecord in order to perform this operation.",
Depends, which script type is this? User Even scripts for example, loading/saving the record would result in an error.

How to perform SubmitFields onto a custom record in SuiteScript 2.0?

To perform SubmitFields onto standard Netsuite Records (i.e. Purchase Orders) it is something like this:
var poId = context.key;
var id = record.submitFields({
type: record.Type.PURCHASE_ORDER,
id: poId,
values: {
custbody_someField: someValue
},
options: {
enableSourcing: false,
ignoreMandatoryFields : true
}
});
What is the type field for Custom Records? I tried the ID of the Custom Record, but it doesn't work:
e.g.
type: record.Type.customrecord_my_record_id
I don't know what the 'official' answer is. The fake enum types don't have any custom record references that I was able to find. Setting the type to the string that is the id of the custom record works for me. (No record.Type. prefix though)
... type: "customrecord_my_record_id", ...
That is true that the references are only for standard record types. You can alternatively get all enums into a variable and log it using
var recordTypesEnums = Object.keys(record.Type);
//you may log recordTypesEnums array

How to replace object ID with alias in URL

I have just installed keystone.js and build basic site.
However I noticed that URL contains the mongoDB ID of length 24. that looks ugly.
Any Idea, how can I change it.
http://localhost:3000/keystone/users/56ed6816491debf405f99be1
http://localhost:3000/keystone/posts/56ed086c4b4ba4f8044bbbe1
I want it to be like
http://localhost:3000/keystone/users/enraiser
http://localhost:3000/keystone/posts/my-first-post
We can use auto key of keystones
var Post = new keystone.List('Post', {
autokey: { path: 'slug', from: 'title', unique: true },map: { name: 'title' },
defaultSort: '-createdAt'
});
Create auto-incrementing id field:
https://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/

how to validate dynamic key of mongoose schema

I am trying to build a MEAN project, so I need to validate some of my model's dynamic key...
I want to create a Schema like this
var exampleSchema = new Schema({
x: {
type: String,
default: '',
required: true,
trim: true
},
y: {}
});
as you see I have mixed type object, but actually it is a Language Map and it should be something like this,
{
"en-US": "answered"
}
can I validate my key with mongoose? (I think it has no function like that)
if no, how and where can I validate it (in model or controller)?
You may want to look into this: http://mongoosejs.com/docs/middleware.html
Specifically pre-save events. Mongoose gives you control over this and you can perform validation, mapping as needed before the actual model gets saved.
Also works nice for pre-init event if you need defaults such as "current date" for an audit trail such as "createdOn: date".

Resources