What is the 'Primary Information' field group id in NetSuite? - netsuite

In my User Event script I am adding a field to the form and I would like to add it to the Primary Information field group. What is the internal id of the group? I've tried primaryinformation but that's not correct. I can't see a method of iterating field groups and fields in the API to figure it out.
Does anyone know?
I am using SS2.
var field = scriptContext.form.addField({
id: 'textfield',
type: serverWidget.FieldType.TEXT,
label: 'Text',
container: '**primaryinformation**' <--
});

From inspecting the DOM of the form, it looks like they are randomly generated identifiers in the form fieldGroupXX.
As an alternative, you could try using form.insertField(options) to place your field in the desired Field Group.

Related

SuiteScript 2.0 - Load Custom Record Table Data

Within Customization -> List, Records & Fields -> Custom Records I have a table with id: customrecord_{name} with the type "customrecordtype". I have multiple fields in that record
How can I use the load function to get all the data for this table/record? (For all the fields)
const data= record.load({
type: 'customrecord_{name}',
isDynamic: false
... //get all fields
});
I tried to look at the help center but am a bit lost on how to accomplish this.
As far as I know load won't do it. After loading a custom record with load, you can check all the fields of this custom record by calling data.getFields() method. This will return a list of field ids (including custom ones) that you can fetch by calling data.getValue such as data.getValue({'fieldId':'isinactive'}) // a regular field or data.getValue({'fieldId':'custrecord_routeproduce_highpriority'}) // a custom field
loading a custom record, checking its fields, fetching value of a custom field

NetSuite SuiteScript 2.0 get Company Name

Is there any way to get the current company name when on a transaction entry page? Either some session object, global object, or some sort. Kind of like how you can get the user name from the runtime module? I see country name, but cannot seem to get the company name. Using a client script for this.
How I get the user name:
runtime.getCurrentUser().name
thank you
Here is the working code now, but trying to figure a way to get this on a client script. Possible to pass this value?
var companyInfo = config.load({
type: config.Type.COMPANY_INFORMATION
});
var compname = companyInfo.getValue({
fieldId: 'companyname'
});
log.debug(compname);
scriptContext.form.addButton({
id: "custpage_mybutton",
label: "View Documents",
functionName: "onButtonClick"
});
scriptContext.form.clientScriptModulePath = "SuiteScripts/dl_cs_vendorbill.js";
In server side scripts you can do this:
require(['N/config'], config=>{
const info = config.load({type:config.Type.COMPANY_INFORMATION});
log.debug({title:'Current company Info', details:info.getValue({fieldId:'companyname'}));
});
For a client script you could use that code in a paired user event script.
In the before phase of the UE you'd do the lookup and then add a hidden field to the form with the company name as a value. Your client script can then look that up like any normal getValue

How to lookupfield in lines of Client script API 2.0?

i need to pick a field from item master record. The item type is sometimes service item and sometimes itemgroup. There is some issue in record 'type' and 'id'. Please help.
My Code:
var govFeeFieldInside = search.lookupFields({
type: search.Type.ITEM,
id: item_,
columns:
[
'custitem2'//govFeeInItemMaster
]
});
lookupFields is only for body-level fields. To retrieve sublist data from any record, you will need to either perform a search or load the record.

How to best reach into MongoDb Mongoose Schema objects which use lists of other objects

I am learning my way around MongoDB data types and the best way to use documents and Schemas through Mongoose.
I've defined a couple of Schemas for a Navigation bar object which stores the navigation items as a list, and each item is defined by a schema with the properties name, type, url, and a list of drop downs if it has any (if the type is "dropdown").
Here are those Schemas:
var navSchema = new Schema({
id: String,
items: [Schema.ObjectId]
});
is the nav object, and
var navItemSchema = new Schema({
name: String,
type: {type: String, default: "link"},
url: {type: String, default: null},
dropdowns: {type: [Schema.ObjectId], default: null}
});
is the nav item schema, but each nav item can potentially have dropdowns, and so the dropdowns is a list of nav items, which can also potentially have dropdowns. But in this case, only a few do.
Now to create the data for these objects, I have to do something like this to create a nav item, example for "home"
var home = new navItem({
name: "home",
url: "/home"
});
but for items with dropdowns, I have to define all the items I know will be dropdowns before defining list which includes those items, and then defining the parent item and using the list with those items I just defined. Like this
var allAccessories = new navItem({
name: "all accessories",
url: "/accessories"
});
var cushions = new navItem({
name: "cushions",
url: "/accessories#cushions"
});
var cupHolders = new navItem({
name: "cup holders",
url: "/accessories#cupholders"
});
var accessoriesDropdownItems = [
allAccessories,
cushions,
cupHolders
];
var accessories = new navItem({
name: "accessories",
type: "dropdown",
dropdowns: accessoriesDropdownItems
});
So, I assume I'm doing that right..? My only gripe with this method is that in my nav.js file where I create this mongodb object/collection, I have to think about what items are going to be used in dropdowns of other items, and so I have to theoretically order them to be defined before the other variables are defined in the document.
But if I then want to use an item in two dropdown lists, and one of those dropdownlists I happened to have already defined above it in the document but now want to add to. I have to move the item definition above anywhere it's used, this ruins the organisation of the document..
But I'm okay with physically indenting to keep my work organised and sorted.
My question is how do I actually access properties of objects within lists of other objects.
Straight up I define Nav as simply an object with an id, "nav" because I don't want to use its _id ObjectId to reference it all the time...? And an items array which contains the navItemsSchema objects.
But when I try to reach into these objects through mongo shell using something like
db.navs.find({items: {$elemMatch: {name:"home"}}})
Or
db.navs.find({items: ObjectId("58d5d6df0789f718460ff278")})
Or
db.navs.find({items:{ "name" : "home"}})
I can't get any data back.. I have successfully manage to return all objects in the collection through the node app via responding found nav in navs
app.get('/nav', function(req, res) {
mongoose.model('nav').find(function(err, nav) {
res.send(nav);
});
});
But all this returns me is a data structure with object id's and not the actually data of the objects.
{"_id":"58d5d6df0789f718460ff287",
"id":"nav","__v":0,
"items":
["58d5d6df0789f718460ff278",
"58d5d6df0789f718460ff279",
"58d5d6df0789f718460ff286",
"58d5d6df0789f718460ff281",
"58d5d6df0789f718460ff282",
"58d5d6df0789f718460ff283",
"58d5d6df0789f718460ff284"
]
}
Could you please help me understand how I reach into these data hierarchies via say db.navs.nav("nav").items.findAll() and it lists all the items and their json?
Or is this not possible and you need to loop through all items, then. Wait, where are the objects stored corresponding to ObjectId's in the items list?
So I actually figured it out myself. I was using type: [Schema.ObjectId] (ie. type was a list of Schema.ObjectIds) but I didn't know that that automatically parses the inputted list of objects and extracts just their ObjectId's and stores them, all I need to do was make the type: [] (ie. just a list) and then I can traverse my nav object simply by... Oh wait, for some reason when mongoose nav.saves my nav it becomes an object inside a list. So when I mongoose.model('nav').find(function(err, nav) {} it gives me a nav object which I need to use via nav[0].items[0].name Or I can go nav = nav[0] but I wish I didn't need to do this step? Maybe there's an answer but yes. Otherwise. This is the solution I was looking for.

How to update an index with new variables in Elasticsearch?

I have an index 'user' which has a mapping with field of "first", "last", and "email". The fields with names get indexed at one point, and then the field with the email gets indexed at a separate point. I want these indices to have the same id though, corresponding to one user_id parameter. So something like this:
function indexName(client, id, name) {
return client.update({
index: 'user',
type: 'text',
id: id,
body: {
first: name.first
last: name.last
}
})
}
function indexEmail(client, id, email) {
return client.update({
index: 'user',
type: 'text',
id: id,
body: {
email: email
}
})
}
When running:
indexName(client, "Jon", "Snow").then(indexEmail(client, "jonsnow#gmail.com"))
I get an error message saying that the document has not been created yet. How do I account for a document with a variable number of fields? And how do I create the index if it has not been created and then subsequently update it as I go?
The function you are using, client.update, updates part of a document. What you actually needs is to first create the document using the client.create function.
To create and index, you need the indices.create function.
About the variable number of fields in a document type, it is not a problem because Elastic Search support dynamic mapping. However, it would be advisable to provide a mapping when creating the index, and try to stick to it. Elastic Search default mapping can create you problems later on, e.g. analyzing uuids or email addresses which then become difficult (or impossible) to search and match.

Resources