Friday 21 June 2019

How will you disable line item field without disabling entire column using CLient Script (SuiteScript 2.0)?

Here I came across one of the scenario, like i need to disable a line item field depends upon a condition. So, while doing this change in Client Script, complete column was disabled instead on a single field in a row.

I have used "field.Disabled=true" for disabling the field.

In-fact, as per the Suite Script 2.0 API, documentation provides the definition provides like this:

If you are working with a sublist field, you can set this property to true or  false, but
be aware that this action affects the entire sublist column, even though a sublist field is
associated with one line. 
¦ For both body and sublist fields, you can use Field.isDisabled to determine whether
the field is disabled or enabled.



To overcome the above issue i have followed below steps:

1. Created a client script, under the "lineinit(context)" section, added below lines of Code:

function lineInit(context) {
   
    var invoice = context.currentRecord;

    var selectedLine = invoice.getCurrentSublistIndex({
    sublistId: 'item'
    });
   
    var qty = invoice.getCurrentSublistValue({
   
    sublistId: 'item',
    fieldId : 'quantity',
 

    });
 
    if (qty > 1.0) {
   
    invoice.getSublistField({
   
    sublistId : 'item',
    fieldId: 'description',
    line:0
    }).isDisabled = true;
    }
    else {
   
    invoice.getSublistField({
   
    sublistId : 'item',
    fieldId: 'description',
    line:0
    }).isDisabled = false;
   
    }

    }

Here I have considered "line" number as "0", line is a mandatory option in the .getSublistField() method. The main use of lineinit is, the code is executed when an existing line is selected. Since the code is executed at line level, so everyline will hold line number as 0.


In the above line the Description field is disabled the the item quantity has crossed more than 1.

Note: this will work absolutely fine in SuiteScript1.0 without any line number. below is the method need to be used.
nlapiDisableLineItemField(type, fldnam, val)

Thanks


Sunday 16 June 2019

How do you create Radio buttons in NetSuite ?

As per my knowledge we cannot create a radio field using Suite Customization, like Creating Custom Field, Creating a radio button using workflow is not available.

To Overcome that we can use SuiteScript.  We can create the RADIO button field using the "N/ui/ServerWidget" Module.

Follow below steps to create a radio button in NS:

1. Load the "N/ui/ServerWidget" in server side script, like UserEvet or Suitelet depends upon the requirement,

2. Use "form.addField(options)" to add a field,

Below are the options , which needs to be used:


// Create Radio button for undeposited
        var field2 = context.form.addField({
        id: 'custpage_radiofield',
        type: serverWidget.FieldType.RADIO,
        label: 'Undep.Funds',
        source: 'undepfunds'
        });

/ Create Radio button To select Account
        var field3 = context.form.addField({
        id: 'custpage_radiofield',
        type: serverWidget.FieldType.RADIO,
        label: 'Account',
        source: 'selectaccount'
        });

Use field.setHelpText(options) to set the help text in the fields.

field2.setHelpText({
       
        help : "Select Undeposited Account",
        showInlineForAssistbaonotlean: true
       
        });

 In Radio buttons, the 'id' will be always same, we must have source as unique, we must use source to select the radio buttons.

like  below:

 if (record.getValue('custpage_radiofield') == 'undepfunds' ) {

<< Do something>>

 }

 if (record.getValue('custpage_radiofield') == 'selectaccount' ) {

<< Do something>>

 }

Please go through suitescript 2.0 API document if you need more information.

Thanks


Saturday 15 June 2019

How do you overcome "RangeError:maximum stack size exceeded" error while changing the field in NS page ?

Here I  came across one issue:

I was trying to select a radio button from NetSuite UI, during the change i'm trying to insert an account in client script, and trying to fetch from the list of accounts in UserEvent script,  this happens on the field change so, my client script has triggered recursively hence I have received "RangeError:maximum stack size exceeded" error on my custom page created in NS.
Now, how i have avoided this issue is :

in Client Script, in fieldChanged(context) section:

Apply highlighted line of code:

currentRecord.setValue({fieldId:'custrecord_account', value: acct,  ignoreFieldChange:true});

This way we can solve the maximum stack size errors. There might be many scenario's, but i suggest use ignoreFieldChange:true to solve these kind of issues.


Thanks,
Ram

Tuesday 11 June 2019

How to Hide the Buttons in a NetSuite Page ?


Before proceeding, i want to thank Marty Zigman, and his blog http://blog.prolecto.com.
I got the best help from his blog which helped me to overcome the hiding buttons issue. 

With Suite Flow  (Point and click Customization's)  we cannot hide/remove buttons in the NetSuite page.

Like in Prospect page -> if i need to hide "New Contact", "Attach", "Update Primary", "Customize View" buttons what should I do?

Since with NS Point and Click functionality doesn't support us to hide these buttons, we can use Client side JavaScript to get the control. this kind of programming is called "Document Object Model (DOM)".

Before implementing, we should know below steps:


  1. JQuery: NetSuite provides a reference to the JQuery add-in library by default. Thus it is convenient for DOM operations.
  2. HTML IDs: We need to know the IDs of the target HTML elements we want to manipulate.
  3. Script: We need to inject some client-side JavaScript into the HTML to get ultimate control.
I have followed below approach to hide the buttons in NS:

1. Since i need to hide the buttons in both "View" mode and "Edit" mode, hence I have used "UserEvent Script".

2. Hover on "New Contact" button -> Right Click -> Inspect -> click on it.

3. Verify the "id" for the "New Contact" button in "<input>".
As per below screen:

My Requirement is :

In Prospect record, under "Relationship" subtab:

1. Hide "New Customer", "Attach", "Update Primary" buttons,
2. Role Field

Scripting:

For that, I have chosen below way:

1. Considered UserEvent Script.
2. Creating an "Inline Text Field" and pushing the jQuery into this field.

//create an inline html field
    var hideField = context.form.addField({
    id:'custpage_hide_fields',
    label:'Hidden',
    type: serverWidget.FieldType.INLINEHTML
     });

var src = "";

    // hiding Role field in edit mode
    src += 'jQuery("#inpt_contactrole10").hide();';
    src += 'jQuery("#inpt_contactrole10_arrow").hide();';
   
        //hiding buttons
        src += 'jQuery("#newcontact").hide();';
    src += 'jQuery("#addcontact").hide();';
    src += 'jQuery("#updatecontact").hide();';
    src += 'jQuery("#tbl_newcontact").hide();';
    src += 'jQuery("#tbl_addcontact").hide();';
    src += 'jQuery("#tbl_updatecontact").hide();';

        //hiding Role Field in view mode
        src += 'jQuery("#contact_contactrole_fs_lbl_uir_label").hide();';
    src += 'jQuery("#inpt_contactrole1").hide();';
    src += 'jQuery("#inpt_contactrole1_arrow").hide();';
   
    log.audit(src)
    // default the 'src' data in the created inline html field
     hideField.defaultValue = "<script>jQuery(function($){require([], function(){" + src + ";})})</script>"

This entire code considered under beforeLoad section.Since we are creating new field we must consider "N/ui/serverWidget" module,. please go through SuiteScript 2.0 for more details.

Below are the results:

In View Mode:

In Edit Mode:


This code changes works in all browser's, these code changes are not specific to any browser.

Now, We know how to hide the fields with server side script, can we hide the buttons using client side script ?

Answer is Yes, with limitations.

Since the Client Script works in "Edit" mode, the buttons will be hidden in only Edit mode not in View mode.

So, by using UserEvent script will help me to hide buttons in both  View and Edit modes.

Please go through below link for more details. Write to me if any issues, or any better solutions available.

http://blog.prolecto.com/2018/09/22/learn-how-to-hide-netsuite-sublist-buttons-and-other-html-elements/

Thanks,
Ram

Sunday 9 June 2019

How to Create a Journal Entry in NS using SuiteScript 2.0 ?

What is a journal ?

A journal is a detailed account that records all the financial transactions of a business, to be used for future reconciling of and transfer to other official accounting records, such as the general ledger. 

A journal states the date of a transaction, which accounts were affected, and the amounts, usually in a double-entry bookkeeping method.

How can we create a Journal entry in NS? (Considering Classic Center)
Go to Transactions -> Financial -> Make Journal Entries (click on it).
We must enter credit and debit lines for balancing.
If any situation comes like, to create an automated JE using suiteScript 2.0, below is the way we can do:

var journal = record.create({
    type : record.Type.JOURNAL_ENTRY, (<< you can search for the Enum value in SuiteScript2.0 API provided by NS>>)
    isDynamic : true
    });
   
//set the values in the required fields in JE main section
    journal.setValue('subsidiary',subsidiary);
    journal.setValue('trandate',date);
    journal.setValue('memo',"Creating journal")
   
// Credit line
    journal.selectNewLine('line');
//Set the value for the field in the currently selected line.
    journal.setCurrentSublistValue('line','account',Acct);
    journal.setCurrentSublistValue('line','credit', Amt);
    journal.setCurrentSublistValue('line','memo',"Account Balancing");
    //Commits the currently selected line on a sublist.
journal.commitLine('line');
   
// Debit Line
    journal.selectNewLine('line');
//Set the value for the field in the currently selected line.
    journal.setCurrentSublistValue('line','account',depAcct);
    journal.setCurrentSublistValue('line','debit', checkAmt);
    journal.setCurrentSublistValue('line','memo',"Account Balancing");
//Commits the currently selected line on a sublist.
    journal.commitLine('line');
    //save the record.
    journal.save();

In the above code, we are trying to create a journal entry in dynamic mode.

This should work, in case please let me know.

Thanks

Friday 7 June 2019

How to Void any transaction using SuiteScript 2.0 ?

We should use transaction.void() method to void any transaction.

Imp: After you void a transaction, you cannot make changes to the transaction that impact the general ledger.

If a Void is performed on a transaction, then it returns the ID of the recorded void transaction.

Here is sample code:

var voidCustPaymentId = transaction.void.({
type: record.Type.CUSTOMER_PAYMENT,
id: payment.id <<'Give the Id of the transaction here'>>
});

make sure follow below steps while voiding:

1. In the 'define' function use - N/transaction module,
 Reason is the transaction.void(options) is available in  'N/transaction' module.

2. verify below setup :
    NS ->Go to Setup --> Accounting - > Preferences -> Accounting Preferences:


if the VOID TRANSACTIONS USING REVERSING JOURNALS   field is checked then, we won't see the Void button in the below transactions:

  • Check
  • Bill Payment
  • Payroll Liability Payment
  • Customer Refund
  • Tax Payment
  • Tax Liability Check
  • Customer Payment
and your code will fail.

To avoid this this issue follow make sure you disable the setting and re enable the setting using the code like below:

 use ->'N/config' in the define function.

use below highlighted code:

var revVoid = accountingConfig.getValue('REVERSALVOIDING');

// Uncheck the Reversal flag    
if (revVoid) {
 
           accountingConfig.setValue({
                      fieldId: 'REVERSALVOIDING',
              value: false
            });
accountingConfig.save();

}
//load the payment record
          var paymentValue = record.load({
            type : 'customerpayment',
            id : payment.id
        });
// void the payment record
var voidpayment = transaction.void({
           type: record.Type.CUSTOMER_PAYMENT,
    id: payment.id
      });
       //Reset the reversal flag
accountingConfig.setValue({
fieldId: 'REVERSALVOIDING',
value: true
 });
 accountingConfig.save();
}

This will ensure Accounting settings are not effected.

Note: Make sure if you are using eclipse for suitescripting , some times the transaction.void() results error, this is just because the the jar's are not updated. Ignore the error and load the script in NS, your script should work.


Using SuiteScript2.0 how do Sublist Changes by changing the default account in Make Deposit Transaction?

I came across below issue, for one of my User Event Scripts, when i tried to set the account using suite script, using ".setValue('account','<account number>'); " the sublist was not changing.

Instead i tried below way, While creating the record, set the account in defaultValues. This ensures that the sublist filter the results according to the default value selected.




function createDeposit(depAcctNew,checkDateNew,paymentIdNew) {

var createDeprec = record.create({
type : record.Type.DEPOSIT,
isDynamic : true,
defaultValues: {
account : << give the default account here>>

}
   
});