This topic contains 2 replies, has 0 voices, and was last updated by nathanah 12 years, 4 months ago.

  • Author
    Posts
  • #4848

    nathanah

    Thank you for the new IDE!!

    In some of the demos I saw of the IDE they were showing off putting meta tag information for functions so you can define what objects are being passed in and returned and have the intellisense automatically work. I can’t seem to find any of that documentation anywhere. Is it somewhere that I’m missing or when will it be available?

    Thanks!
    This is a cached copy. Click here to see the original post.

  • #4849

    August Li

    RE: Metatag Documentation

    hi, documentation is not yet finalized, but here is something to get you started.

    Introduction to JSDoc

    JSDoc is based on JavaDoc, but includes variable type in the declaration. It is supported natively in Eclipse, but we added a few tags of our own.

    Shortcut in Eclipse is to type /** above a function and press Enter.

    Code:
    /** This is a JSDoc comment, take note of the double asterisks. */
    /* This is a normal comment but not a JSDoc comment. */
    For a function, you can document the parameters and returns.

    Format of a standard JS Doc comment for a function:

    Code:
    /**
    * @param {parameterType} parameterName ParameterDescription
    * @returns {returnType} ReturnsDescription
    */
    function functionName(parameterName) {
    return null;
    }
    Example usage:

    Code:
    /**
    * @param {String} id Record Internal ID
    * @returns {nlobjRecord} Returns a NetSuite record object
    */
    function example(id) {
    return null;
    }
    Using @type to specify the variable type for variable declarations (var keyword).

    “” in the code means pressing CTRL-SPACE and not its literal text.

    Code:
    /* Using the @type to specify the variable type */
    function func() {
    return null;
    }
    function typeExample() {
    var rec1 = func();
    //#1 try ctrl-space at rec1. (there will be no code completion
    // proposal because rec1’s type is unknown)
    rec1.

    /** @type nlobjRecord */
    var rec2 = func();
    //#2 try ctrl-space at rec2. (with the @type specified, the IDE knows
    // it is of the type nlobjRecord and displays its methods)
    // however, for this particular case, even if we know the type to be
    // nlobjRecord, we don’t know what record it is (e.g. salesorder,
    // account, etc) this will be handled by another tag we will show
    // later on
    rec2.
    }
    At this point, everything mentioned above is standard JSDoc, no custom NetSuite tags yet. There are more tags to JSDoc, but we won’t be discussing it here.

    Next, we will now discuss the @appliedtorecord and @record custom NetSuite JSDoc tags and how they work with standard JSDoc tags.

    Using the @appliedtorecord tag

    The @appliedtorecord tag is set at function level, this corresponds to the “Applied To” record in the script deployment and

    is applicable only for functions that rely on the above mentioned “Applied To” field.

    This is applicable for client and user event scripts only.

    There can be multiple tags and the resulting fields are combined from multiple records.

    For example, in a client script with On Save event, the tag will let the IDE know that you are working with a “customer” and “lead” record

    and it will display fields for the two records in your function calls.

    In the absence of these tags, fields for all records will be displayed.

    Code:
    // create a JSDoc comment above a function and
    // add the @appliedtorecord tag and record

    /**
    * @appliedtorecord customer
    * @appliedtorecord lead
    *
    */
    function clientSaveRecord(){
    // when using functions that rely on the script deployment record
    // type such as nlapiGetOldRecord
    var oldRec = nlapiGetOldRecord();
    oldRec.getFieldText(”);
    // fields will be displayed for customer and lead only in the
    // parameter for oldRec.getFieldText()
    return true;
    }
    Using the @record tag

    The @record tag can be added under the @param and @returns JSDoc tags.

    There can be multiple @record tags and the resulting fields are combined from multiple records.

    It can be used in conjunction with @param, @returns and @type.

    Demonstrate how @record works with @returns

    Code:
    /**
    * @param {nlobjRecord} recordObject
    * @record salesorder
    * @record account
    *
    * @returns {Boolean}
    */
    function recordTagExample(recordObject) {
    recordObject.setFieldValue(”, null);
    //fields for salesorder and account are displayed
    //because we have @record tags under the @param line
    }
    Demonstrate how the @record works with @returns

    Code:
    /**
    * This specifies that the function will return an nlobjRecord type
    * which is a cashsale record.
    *
    * @returns {nlobjRecord} NetSuite record object
    * @record cashsale
    */
    function getRecord() {
    return null;
    }
    var rec = getRecord();
    rec.setFieldValue(”, null);
    //fields for cashsale will be displayed
    Demonstrates how to use @record in conjunction with @type

    Earlier we already showed how the @type tag works for code completion of function names and methods,

    now we show how @record tag works for code completion of internal ids.

    Code:

    // No JSDoc tags for this function
    function getCustomer() {
    }

    /** @type nlobjRecord
    * @record customer
    */
    var cust = getCustomer();
    cust.setFieldValue(”, null);
    //fields for customer will be displayed
    return true;

  • #4850

    nathanah

    RE: Metatag Documentation

    This is what I was looking for. I’ll try it out. Thanks!!

You must be logged in to reply to this topic.