Tip 20: How can I use a search on Document(file) type in Netsuite SuiteScript (1.0 & 2.0)

Hello Friend,

Its always advised to avoid using saved searches  in scripting as there may be a chance of getting deleted either knowingly/unknowingly.

But there are certain searches which are not included in Search.Type like below example:

While working on a requirement, I realized to add a search on File. As I suggested above I always prefer to use search created in script rather than using a saved search.

But unfortunately I didn’t find any Search.Type for File/Document Type.

So below code was showing error Type Document is not a Valid type in Search.

var mySearch = search.create({
                type: Search.Type.DOCUMENT,
                filters : myFilters,
                columns : myColumns
            });

 

Then I checked in Saved Search and Document type is available there.

Not sure why Netsuite has that difference in Search.Type and Saved Search Type.

Then I created a saved search using Document type and loaded that search in my script as I have no other option.

saved_seach
Fig 1 – Saved Search On Document Record

I recommend to use word like “(Used By Script)” or “(DO NOT DELETE)” in saved search name, so that if somebody will see that saved search, he will be able to understand, this saved search is used for some script. So risk of getting deleted will be reduced to somewhat.

So, here a simple suggestion to all who has similar issues:

If something is not happening using search.create(), try creating saved search on same search type and use search.load() and use that as search.load() doesn’t need any type parameter.

           //Load Saved Search created already with selected id as filter
            var mySearch = search.load({
                id: ‘customsearch_search_file’
            });

I have used SuietScript 2.0 in my sample code. You can refer to SuiteScript 1.0 accordingly if you need.

Hope that will help you.

Happy Coding 🙂

Thanks,

Asha

Tip 19: Add Filter to search.load in Netsuite Suitescript 2.0

Hello Friends,

We all know how to add filters while creating a search in Suitescript, as search.create() has a parameter called filters.

Still I am adding it here for anybody who finds difficult to create a search:

var mySearch= search.create({
type: “folder”,
columns: [
“name”,
“internalid”,
“numfiles”
],
filters: [
search.createFilter({
name: ‘name’,
operator: search.Operator.IS,
values: [folderName]
})
]
});

 

Now let’s see how can we add filter to an already existing saved search created either in UI or by search.create() & then search.save().

    var mySearch = search.load({
id: ‘customsearch_test_search’
});
//Add Filter to search
var filter1 = search.createFilter({
name: ‘name’,
operator: search.Operator.IS,
values: [selectedName]
});
mySearch.filters.push(filter1);

I hope this small tip will help you.

Happy Coding 🙂

Tip 18: Setting DisplayType of field in Suitescript 2.0

Hello Friends,

As I have mentioned in my previous tip, in Suitescript 2.0 developer guide, few points are mentioned wrongly as below.

If you look for how to set display type of a field in either help or guide, you will find as below image.

display_type

But when you use the same syntax its not allowing to upload the code that is

displayType = serverWidget.FieldDisplayType.HIDDEN

But when I changed the syntax by replacing “=” to “:” as below

displayType : serverWidget.FieldDisplayType.HIDDEN

it worked 🙂

Try the same trial method, if you face similar issue.

Hope this trick will help you.

Tip 17: Setting Checkbox in Suitescript 2.0

Hello Friends,

I am exploring Suitescript 2.0 recently and learning new things day by day and I believe I should share it with you all who are also learning Suitescript 2.0.

There are some features which either you won’t get it in document or its wrong in Developer Guide of Suitescript 2.0

Even though its mentioned that in Suitescript 2.0 Checkbox value returns true/false rather than “T”/”F” unlike in Suitescript 1.0, but remember, when you will set Checkbox value use “T”/”F” not true/false.

var fldObj = form.addField({
                    id: ‘custpage_fld_chkbox’,
                    type: serverWidget.FieldType.CHECKBOX,
                    label: ‘Extracting Account?’,
                    container : ‘custpage_tab1’
});
fldObj.defaultValue = ‘T’;

Hope this small tip will save your time and effort.

I will keep on adding tip on Suitescript 2.0

Happy Coding 🙂

 

Tip 16 – Update Subscriptions in Contact Record

Hello Friend,

Recently I got a requirement like, we will have to update Subscriptions in Contact record and I was told that, Netsuite Support team says, its not possible to update it in Contact record through scripting.

I tried even after knowing its not possible as suggested by Netsuite Support.

Even in Record Browser, you won’t find any sublist/fields related to Subscriptions in Contact record.

I checked in Record Browser for Customer and tried checking how it works in Customer record.

Then I tried the same sublist and field IDs in Contact record to update Subscriptions.

You won’t believe, that worked.

Here is the sample piece of code that I am introducing to update Subscriptions in Contact Record:

var contactRecord = nlapiLoadRecord("contact",983);
var subCount = contactRecord.getLineItemCount("subscriptions");
		
//Billing Communication = 2, Marketing=1, Newsletters=4, Product Updates=5, Surveys=3
if(subCount > 0){
	for(var count = 1; count <= subCount; ++count){
		var sub = contactRecord.getLineItemValue("subscriptions", "subscription", count);
		var isChecked = contactRecord.getLineItemValue("subscriptions", "subscribed", count);
		nlapiLogExecution("DEBUG", "sub - isChecked", sub + " - " + isChecked);
				
		if(isChecked == "F"){
			contactRecord.setLineItemValue("subscriptions", "subscribed", count, "T");
		}
		else{
			contactRecord.setLineItemValue("subscriptions", "subscribed", count,"F");
		}
	}
}
var contactId= nlapiSubmitRecord(contactRecord);
nlapiLogExecution("DEBUG", "Contact record submitted", contactId);

Hope when you will get such requirement, you won’t need Netsuite Support’s help 🙂

Cheers

Asha

Tip 14 – Show sub customer’s Transactions on Parent Customer’s record as sublist

Hi Friends,

Coming back again with a new simple tip, that will help you, as this is very common requirement, that every Netsuite account owner needs.

Requirement was like: As a Netsuite user, I should see all Sales Order created by all the sub customers on parent customer as a sublist.

As per Netsuite’s standard functionality, customer record shows all the transacts created by that customer only.

Solutions:

Fortunately the requirement is achieved by Saved Search. How??? Check below steps…

Step 1: Create a Saved Search on Customer record

A)Set Criteria:

1.Type: is Sales Order

2.Main Line: is True

cost-center3

B)Set Results:

Add fields as shown below figure:

cost-center1

C)Set Available Filters:

Add Field Parent:Internal ID in Available Filter section as shown below.

cost-center2

Now Save the Saved Search.

Step 2:

1.Go To Customization -> Forms -> Sublists as below.

cost-center5.png

Now click Entity Tab and select the saved search that you have created just now. Add the tab on which you want to show and select Customer checkbox as shown below.

cost-center6.png

Now add and save.

Now Go to the Customer record -> Sales -> Cost Center Transactions and see the results.

cost-center4.png

 

I hope this will help you guys and this is specially for someone who is very new to Netsuite.

 

Thanks,

Asha

 

 

Tip:13 – Add Link to text in results of Netsuite Saved Search

Most of us must have faced the issue of Record Number/Name not displaying as a link but as a text in saved search results.

When in a saved search result, we need to show Parent -> Child -> Sub Child’s field, its difficult to create saved search on Parent record.

So we approach with saved search on Child Record, so that we can fetch column on Parent as well as its child’s column like:

Parent’s Fields<- Child -> Child’s Fields

But we need to make sure, that the saved search results should appear like the saved search is on Parent’s record.

In that condition sometimes, we won’t get link on Parent’s fields like its Number, its Customer/Vendor, so that on click of the link, we should redirect to Parent’s record instead of Child’s record.

Saved Search

I would link to share my findings on the same issue.

Solution:

Instead of adding Number/Customer Name/Vendor Name, add Formula(Text) in results column.

Ex:  For Number:

Column: Formula(Text)

Formula: ‘<a href = https://system.na1.netsuite.com/app/common/custom/custrecordentry.nl?rectype=484&id= ‘||{custrecord1401.internalid}||’>’||{custrecord1401.name}||'</a>’

Here remember below points:

  1. Use “<a>” HTML tag for adding link to the specific field in results.
  2. The “href”  value should be the address URL same as to open a new record of that type like: “<a href = https://system.na1.netsuite.com/app/common/custom/custrecordentry.nl?rectype=484&id=
  3. Netsuite uses “||” while adding fields to HTML tags. Use carefully while adding this symbol. Use “||” before and after the field name like ||{custrecord1401.name}||.
  4. ||{custrecord1401.name}|| should always be within single quote() like ‘||{custrecord1401.name}||’.
  5. Use the field within “<a>” & “</a>” like ” ‘<a>’||{custrecord1401.name}||'</a>’ “.
  6. Now add the internal ID field for “id=” parameter in the URL like: ‘<a href = https://system.na1.netsuite.com/app/common/custom/custrecordentry.nl?rectype=484&id= ‘||{custrecord1401.internalid}||’>’||{custrecord1401.name}||'</a>’.
  7. DON’T  use “+” sign while adding id field to the parameter that we generally do for other languages.
  8. Now click Add and “Save & Run”. Now you must be able to see the link on the Number/Name. On click of that, you must be redirected to that record.

Hope this tip will help you.

Comments/Suggestions are appreciated.

Thanks,

Asha