Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

596
Views
SuiteScript 2.x entry point scripts must implement one script type function

I added a field in the Sales Order named Membership that will source from the customer record. Then when that field is set to the membership level (ex. elite member) it automatically set the discount item field to a specific discount item.... I encountered a notif saying SuiteScript 2.x entry point scripts must implement one script type function how do I fix this?

/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */
define(["N/currentRecord", "N/runtime"], function(currentRecord,runtime) {

    function pageInit(context) {

     const record = currentRecord.get()  // Get value of Membership Field   
     const user = runtime.getCurrentUser().name
    }
    
    var membership = currentRecord.getField({
        fieldId : "custentity1",
    })

    if(membership == "Elite"){
        //Setting up discount
        record.setValue({
            fieldId: "discountitem", //fieldId of the Discount Item 
            value: 137 // Internal ID of the Discount Item
        })}

        else {
            record.setValue({
                fieldId: "discount item",
                value: 0
            });
        }

        return {
            pageInit : pageInit
        }
});    
about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

your code needs to be in an entry point for it to have an affect on the Sales Order record, sounds like you want to use the fieldChanged entry point, look at that in the help docs.

about 4 years ago · Santiago Gelvez Report

0

Your logic must be present within the function i.e. the Entrypoint functions. In your code, it is outside the function (PageInit function). Hence the error.

Try this -

/** 
  *@NApiVersion 2.0
  *@NScriptType ClientScript
*/ 

define(["N/currentRecord", "N/runtime"], function(currentRecord,runtime) {

    function pageInit(context) {

        const record = currentRecord.get();  // Get value of Membership Field   
        const user = runtime.getCurrentUser().name;

        var membership = currentRecord.getField({
            fieldId : "custentity1"
        });
           
        if(membership == "Elite"){
            //Setting up discount
            record.setValue({
                fieldId: "discountitem", //fieldId of the Discount Item 
                value: 137 // Internal ID of the Discount Item
            });
        } else {
            record.setValue({
                fieldId: "discount item",
                value: 0
            });
        }
    }
       
    return {
        pageInit : pageInit
    }
});

Let me know in case of issues.

about 4 years ago · Santiago Gelvez Report

0

Because your using 2.x your global settings are going to determine if this is run as 2.0 or 2.1. I'm guessing you have it set at 2.1 because you're context is having an issue.

If you try to run 2.1 code on the client then you might run into issues. One of those issues is that the context will not be populated. Perhaps this is why you are using currentRecord.get() instead of context.currentRecord ?

Note: Any code that is outside a function (like pageInit) will be run when the module's callback is run.

   if(membership == "Elite"){
    //Setting up discount
    record.setValue({
        fieldId: "discountitem", //fieldId of the Discount Item 
        value: 137 // Internal ID of the Discount Item
    })}

    else {
        record.setValue({
            fieldId: "discount item",
            value: 0
            });
    }

so this code is running before pageInit, so the suggestion by Sayeesh is a good one.

You are mixing some EcmaScipt versions. I would get a good linter like eslint and make sure you are writing code for the target you want.

you got a field called discount item and one called discountitem? I'll assume that is a typo.

To play devil's advocate i'm going to say that you can use 2.1 if you really want to here. In 2.1 you're code could be as simple as : (not checked)

/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 */

define(['N/record','N/currentRecord'],(record,currentRecord)=>{
  return {
    pageInit({ currentRecord : { id, type } }){
        
        const 
          so = record.load({ id, type }),
          membership = so.getValue({ fieldId : 'custentity1' }),
          fieldId = 'discountitem',
          value = membership === 'Elite' ? 137 : 0;
       


        so.setValue({ fieldId, value }); 
    }
  }
}); 
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!