खोज…


पैरामीटर

पैरामीटर विवरण
सुइटस्क्रिप्ट 2.0 -
scriptContext { Object }
scriptContext.newRecord { N/record.Record } डेटाबेस से लोड किए जा रहे रिकॉर्ड का संदर्भ
scriptContext.type { UserEventType } क्रिया प्रकार जिसने इस उपयोगकर्ता ईवेंट को ट्रिगर किया है
scriptContext.form { N/ui/serverWidget.Form } यूआई फॉर्म का एक संदर्भ जो प्रदान किया जाएगा
सुइटस्क्रिप्ट 1.0 -
type { Object } वह क्रिया प्रकार जिसने इस उपयोगकर्ता ईवेंट को ट्रिगर किया है
form { nlobjForm } nlobjForm जाने वाले UI फ़ॉर्म का संदर्भ
request { nlobjRequest } HTTP GET अनुरोध; ब्राउज़र अनुरोधों द्वारा ट्रिगर होने पर ही उपलब्ध है

टिप्पणियों

beforeLoad

रिकॉर्ड पर किसी भी रीड ऑपरेशन Before Load इवेंट चालू हो जाता है। किसी भी समय एक उपयोगकर्ता, एक स्क्रिप्ट, एक सीएसवी आयात, या एक वेब सेवा अनुरोध डेटाबेस से एक रिकॉर्ड को पढ़ने का प्रयास करता है, Before Load घटना निकाल दी जाती है।

रिकॉर्ड कार्रवाई जो beforeLoad घटना को ट्रिगर करती है:

  • सृजन करना
  • संपादित करें
  • देखें / लोड करें
  • प्रतिलिपि
  • छाप
  • ईमेल
  • जल्दी देखो

के लिए विशिष्ट उपयोग मामलों beforeLoad

  • उपयोगकर्ता द्वारा इसे देखने से पहले यूआई फॉर्म को संशोधित करें
  • डिफ़ॉल्ट फ़ील्ड मान सेट करें
  • डेटा पूर्व प्रसंस्करण

उपयोगकर्ता ईवेंट चेन नहीं करते हैं

उपयोगकर्ता ईवेंट में लिखा गया कोड किसी भी उपयोगकर्ता ईवेंट को अन्य रिकॉर्ड पर ट्रिगर नहीं करेगा। उदाहरण के लिए, से संबद्ध ग्राहक रिकॉर्ड लोड हो रहा है beforeLoad एक बिक्री आदेश रिकॉर्ड की ग्राहक रिकॉर्ड के ट्रिगर नहीं करेगा beforeLoad । यहां तक कि अगर आप एक और लेन-देन रिकॉर्ड लोड कर रहे हैं, तो भी इसके उपयोगकर्ता ईवेंट को निकाल नहीं दिया जाएगा।

नेटसुइट एक अनंत लूप में एक दूसरे को ट्रिगर करने वाले उपयोगकर्ता ईवेंट से बचने के लिए ऐसा करता है। यदि आप एक श्रृंखलित अनुक्रम में आग की जरूरत उपयोगकर्ता घटनाक्रम करते हैं, अन्य स्क्रिप्ट प्रकार (जैसे RESTlets, Suitelets, अनुसूचित स्क्रिप्ट) घटनाओं के बीच में इंजेक्ट किया जा करने की आवश्यकता होगी।

इवेंट हैंडलर void देता void

beforeLoad घटना हैंडलर का रिटर्न प्रकार void । हमारे ईवेंट हैंडलर से लौटाए गए किसी भी डेटा का सिस्टम पर कोई प्रभाव नहीं पड़ता है। हमें अपने हैंडलर फ़ंक्शन से कुछ भी वापस करने की आवश्यकता नहीं है क्योंकि हम वास्तव में इसके लौटे मूल्य के साथ कुछ भी नहीं कर सकते हैं।

न्यूनतम: लोड करने से पहले एक संदेश लॉग ऑन करें

// 1.0
function beforeLoad(type, form, request) {
    nlapiLogExecution("DEBUG", "Before Load", "type=" + type);
}

// 2.0
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(["N/log"], function (log) {
    function beforeLoad(context) {
        log.debug({
            "title": "Before Load",
            "details": "type=" + context.type
        });
    }

    return {
        "beforeLoad": beforeLoad
    };
});

UI फ़ॉर्म को संशोधित करना

// 1.0
// Revealing Module pattern, structures 1.0 similar to 2.0
var myNamespace = myNamespace || {};
myNamespace.example = (function () {

    /** @appliedtorecord employee */
    var exports = {};
    
    function beforeLoad(type, form, request) {
        showBonusEligibility(form);
    }

    function showBonusEligibility(form) {
        var field = form.addField("custpage_is_bonus_eligible",
            "checkbox", "Eligible for Bonus?");
        field.setDefaultValue(isEligibleForBonus(nlapiGetNewRecord()) ? "T" : "F");
    }

    function isEligibleForBonus(rec) {
        // Implement actual business rules for bonus eligibility here
        return true;
    }
    
    exports.beforeLoad = beforeLoad;
    return exports;
})();

// 2.0
/**
 * @appliedtorecord employee
 * @NScriptType UserEventScript
 * @NApiVersion 2.x
 */
define(["N/log", "N/ui/serverWidget"], function (log, ui) {
    var exports = {};
    
    function beforeLoad(context) {
        showBonusEligibility(context.form);
    }
    
    function showBonusEligibility(form) {
        var field = form.addField({
            "id": "custpage_is_bonus_eligible",
            "label": "Eligible for Bonus?",
            "type": ui.FieldType.CHECKBOX
        });
        field.defaultValue = (isEligibleForBonus() ? "T" : "F");
    }

    function isEligibleForBonus(rec) {
        // Implement actual business rules for bonus eligibility here
        return true;
    }
    
    exports.beforeLoad = beforeLoad;
    return exports;
});

उपयोगकर्ता ईवेंट को ट्रिगर करने वाली कार्रवाई के आधार पर निष्पादन को प्रतिबंधित करें

// 1.0
// Utilize the type argument and raw Strings to filter your
// execution by the action
function beforeLoad(type, form, request) {
    // Don't do anything on APPROVE
    // Note that `type` is an Object, so we must use ==, not ===
    if (type == "approve") {
        return;
    }
    
    // Continue with normal business logic...
}

// 2.0
/**
 * @appliedtorecord employee
 * @NScriptType UserEventScript
 * @NApiVersion 2.x
 */
define([], function () {
    var exports = {};
    
    // Utilize context.type value and context.UserEventType enumeration
    // to filter your execution by the action
    function beforeLoad(context) {
        // Don't do anything on APPROVE
        if (context.type === context.UserEventType.APPROVE) {
            return;
        }
        
        // Continue with normal business logic...
    }
    
    exports.beforeLoad = beforeLoad;
    return exports;
});

उपयोगकर्ता ईवेंट को ट्रिगर करने वाले संदर्भ के आधार पर निष्पादन को प्रतिबंधित करें

सुइटस्क्रिप्ट 1.0 में, हम nlapiGetContext().getExecutionContext() का उपयोग करके वर्तमान निष्पादन संदर्भ को पुनः प्राप्त करते हैं, फिर हम परिणाम की तुलना कच्चे कच्चे तार से करते हैं।

// 1.0 in Revealing Module pattern
var myNamespace = myNamespace || {};
myNamespace.example = (function () {
    var exports = {};
    
    function beforeLoad(type, form, request) {
        showBonusEligibility(form);
    }
    
    function showBonusEligibility(form) {
        // Doesn't make sense to modify UI form when the request
        // did not come from the UI
        var currentContext = nlapiGetContext().getExecutionContext();
        if (!wasTriggeredFromUi(currentContext)) {
            return;
        }
        
        // Continue with form modification...
    }
    
    function wasTriggeredFromUi(context) {
        // Current context must be compared to raw Strings
        return (context === "userinterface");
    }
    
    function isEligibleForBonus() {
        return true;
    }
    
    exports.beforeLoad = beforeLoad;
    return exports;
})();

सुइटस्क्रिप्ट 2.0 में, हम N/runtime मॉड्यूल आयात करके और इसके executionContext गुण का निरीक्षण करके वर्तमान निष्पादन संदर्भ प्राप्त करते हैं। इसके बाद हम इसके मान की तुलना runtime.ContextType के मान से कर सकते हैं। कच्चे स्ट्रिंग्स के बजाय runtime.ContextType एन्यूमरेशन।

// 2.0
/**
 * @NScriptType UserEventScript
 * @NApiVersion 2.x
 */
define(["N/ui/serverWidget", "N/runtime"], function (ui, runtime) {
    var exports = {};
    
    function beforeLoad(scriptContext) {
        showBonusEligibility(scriptContext.form);
    }
    
    function showBonusEligibility(form) {
        // Doesn't make sense to modify the form if the 
        if (!wasTriggeredFromUi(runtime.executionContext)) {
            return;
        }
        
        // Continue with form modification...
    }

    function wasTriggeredFromUi(context) {
        // Context can be compared to enumeration from runtime module
        return (context === runtime.ContextType.USER_INTERFACE);
    }
    
    exports.beforeLoad = beforeLoad;
    return exports;
});


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow