I’m having a dumb moment here. In Client Script o...
# suitescript
j
I’m having a dumb moment here. In Client Script on a Custom Record that has a
name
generated by autonumbering with a prefix (e.g.
ABC0001
), how do I get the name of the record in Client SuiteScript?
it’s coming back as null if I try to get it via currentRecord
also null if I test in SS1 using
nlapiGetFieldValue('name');
c
I just tested this in the console for a custom record w/ name and it came back fine.
Copy code
require(['N/currentRecord'], function(currentRecord) {

    var myRecord = currentRecord.get();
    var name = myRecord.getValue({fieldId: 'name'});
    console.log('Name: ' + name);
});
j
my custom record does not have
Include Name Field
ticked, it’s just a name that gets autogenerated with prefix & minimum number of digits.
c
Do you have the netsuite field explorer addon? You can check that and see if its available. Or add &xml=T to the URL of the custom record and find the right field. It may be something else besides name then.
j
message has been deleted
message has been deleted
the label is “ID” but the field is
name
message has been deleted
just seems like it’s not exposed to
currentRecord
for some reason
c
if it isn't, you could create another field and see if you can non-stored source name into the field and just use that field
j
ugh
not worth it for what I’m trying to do, to be honest
c
I mean worth a shot i guess. Definitely not ideal.
sure
j
it’s crazy that I can’t get the name of the record!
obvs I could saved search or record.load but I don’t want to do that
c
whats your code look like?
just editing the custom record and giving it a go in console?
j
correct
I unearthed the issue when debugging something else as I saw an error in my console that was spawned from a client script I have running on this (and many other) custom records
that client script does something like this
Copy code
var rec = currentRecord.get();
var name = rec.getValue({fieldId: 'name'}); // null
then tries to use the value of
name
to set a value on a different custom record that we use for logging who is editing what records
and failed, cuz
name
is null
e
if you can see it using xml=T you can get to it using my trick by parsing the XML 😉
j
am I not crazy thinking I should just be able to get it from currentRecord? I mean….it’s the fricking NAME of the record.
c
That is so weird. Not sure ive run into that honestly.
j
I feel like I’m overlooking something super obvious here
c
You could add debugger; right after it gets the current record and check it out in the debugger.
Copy code
require(['N/currentRecord'], function(currentRecord) {

    var myRecord = currentRecord.get();
    debugger; // will stop here in the console
    var name = myRecord.getValue({fieldId: 'name'});
    console.log('Name: ' + name);
});
alternatively make another field, source it and be done with it and accept Netsuite sucks sometimes 😄
j
oh I accepted that years ago
hahhah
🤣 1
btw I use tampermonkey so I don’t have to wrap my console SS2 stuff in requires
🙂
c
i have no idea what tamper monkey is
j
Chrome plugin thingy that lets you run JS automatically on certain pages
it’s the 💣
e
hopefully it's not associated with monkeypox! 😉
c
thats pretty cool
j
Copy code
// ==UserScript==
// @name         NetSuite TamperMonkey Base Script
// @namespace    <http://tampermonkey.net/>
// @version      0.2
// @description  Handy-dandy things for the browser in NetSuite
// @author       <myname>
// @match        https://<our_ns_id>.<http://app.netsuite.com/*|app.netsuite.com/*>
// @match        https://<our_ns_id>-<http://sb1.app.netsuite.com/*|sb1.app.netsuite.com/*>
// @match        https://<our_ns_id>-<http://sb2.app.netsuite.com/*|sb2.app.netsuite.com/*>
// @match        https://<our_ns_id>-<http://sb3.app.netsuite.com/*|sb3.app.netsuite.com/*>
// @match        https://<our_ns_id>-<http://sb4.app.netsuite.com/*|sb4.app.netsuite.com/*>
// @match        https://<our_ns_id>-<http://sb5.app.netsuite.com/*|sb5.app.netsuite.com/*>
// @grant        none
// ==/UserScript==

(function() {

    console.log('running tampermonkey');

    'use strict';

    // Resize the popup SuiteScript window because it loads too small to be useful.
    if(location.href.indexOf('&target=filesize&') !== -1)
        setTimeout(function(){ window.resizeTo(1200, 1000); }, 1000);

    // Try to load common modules so that we can use them in the Browser Console.
    try {

        require(['N/currentRecord', 'N/email', 'N/format', 'N/query', 'N/record', 'N/runtime', 'N/search', 'N/ui/message', 'N/url',
                 'N/https', 'N/xml', '/SuiteScripts/2.0/module/md_integrity_ss2.1', '/SuiteScripts/2.0/module/md_cas_ss2.1',
                 '/SuiteScripts/2.0/module/md_moment_ss2.1', '/SuiteScripts/2.0/module/md_records_ss2.1',
                 '/SuiteScripts/2.0/module/md_entity_ss2.1', '/SuiteScripts/2.0/module/md_formatting_ss2.1',
                 '/SuiteScripts/2.0/module/md_query_ss2.1', '/SuiteScripts/2.0/module/md_bignumber_ss2.1'],
			function(currentRecord, email, format, query, record, runtime, search, message, url, https, xml, md_integrity, md_cas,
				moment, md_records, md_entity, md_formatting, md_query, md_bignumber) {

				window.currentRecord = currentRecord;
				window.email = email;
				window.format = format;
				window.query = query;
				window.record = record;
				window.runtime = runtime;
				window.search = search;
				window.message = message;
				window.url = url;
				window.https = https;
				window.xml = xml;
				window.md_integrity = md_integrity;
				window.md_cas = md_cas;
				window.moment = moment;
				window.md_bignumber = md_bignumber;
				window.md_formatting = md_formatting;
				window.md_records = md_records;
				window.query = query;
				window.md_entity = md_entity;
				window.md_query = md_query;
			}
        );

	} catch (error) {

		console.log('Unable to include NetSuite Modules: ' + error);

	}

})();
it’s like running that JS in the browser console after page loads
on every NS page
so then I can just straight up do stuff like record.load() in the console on a single line
c
thats awesome thanks for sharing
j
I think GreaseMonkey is more widely known, same idea
c
never heard of either of them. I like this idea though can def do some stuff
j
alternately, just create a Snippet that loads all your required modules and run that before you start testing in Console
I have a snippet like that
Copy code
require(['N/currentRecord', 'N/email', 'N/format', 'N/query', 'N/record', 'N/runtime', 'N/search', 'N/ui/message', 'N/url', 
	'N/https', 'N/xml', '/SuiteScripts/2.0/module/md_integrity_ss2.1', '/SuiteScripts/2.0/module/md_cas_ss2.1',
	'/SuiteScripts/2.0/module/md_moment_ss2.1', '/SuiteScripts/2.0/module/md_records_ss2.1', 
	'/SuiteScripts/2.0/module/md_entity_ss2.1', '/SuiteScripts/2.0/module/md_formatting_ss2.1', 
	'/SuiteScripts/2.0/module/md_query_ss2.1', '/SuiteScripts/2.0/module/md_bignumber_ss2.1'],
	function(currentRecord, email, format, query, record, runtime, search, message, url, https, xml, md_integrity, md_cas,
		moment, md_records, md_entity, md_formatting, md_query, md_bignumber) {
		window.currentRecord = currentRecord;
		window.email = email;
		window.format = format;
		window.query = query;
		window.record = record;
		window.runtime = runtime;
		window.search = search;
		window.message = message;
		window.url = url;
		window.https = https;
		window.xml = xml;
		window.md_integrity = md_integrity;
		window.md_cas = md_cas;		
		window.moment = moment;	
		window.md_bignumber = md_bignumber;		
		window.md_formatting = md_formatting;			
		window.md_records = md_records;		
		window.query = query;
		window.md_entity = md_entity;
		window.md_query = md_query;	
	}
);
c
I just have a library of methods I just pull from and paste it in but this is way better
j
yah it’s a big time saver
I’ve used TamperMonkey for other stuff too, such as hiding the stupid SuiteApps tab
my Admin NS menu bar is long enough without tabs I don’t use
c
sounds like you have a pretty badass toolkit there
j
I’m a grumpy person by nature, I try to find tools to ungrump myself
c
100% relatable with this job lol
j
💯
d
looks like I am late to the party, but for NS API client modules, you can load all of them without having to specify each:
Copy code
require(['N'], function (N) {
	Object.assign(window, N);
});
🙌 1
I also have something similar setup where actually uses search/query to dynamically pull all relevant custom modules script files I want to load as well:
Copy code
function requireCustomModules() {
	var filesData = getProjectFiles();

	var deps = filesData.map((x) => x.fullPath);

	require(deps, function (...args) {
		args.forEach((e, i) => {
			var moduleName = filesData[i].name.replace('.min', '');

			window[moduleName] = args[i];
		});
	});
}
although you could replace
getProjectFiles
to just hardcode array of the paths to stuff you want, just to reduce a bit more clutter in your example when additional custom modules get progressively added
🙌 1
232 Views