Hello all, can we trigger a suitescript on submit...
# beginners
j
Hello all, can we trigger a suitescript on submit button click. I want to access the ID of the inventory items which are checked as inactive
n
Presuming that is a SuiteLet you have presented you could attach a client script that runs onSave (aka on submit) and direct to / call a SuiteLet
j
@NElliott when I clicked submit button it didn't trigger userEvent. My userEvent script is like this
Copy code
/**
 * Update Inventory Item
 * Sync inventory items information to Magento
 *
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */
define([
    'N/http'
],
    function (http) {

        
        function afterSubmit(context) {
            log.debug('After submit context : ', context);
            
        }
        function beforeLoad(context) {
            log.debug('before submit context : ', context);
        }
        return {
            afterSubmit: afterSubmit,
            beforeLoad: beforeLoad
        };
    });
s
If I remember correctly, the submit button will run in "xedit" context. So instead of trying to run it on the "submit" button (which you can't do), trigger your script everytime there's an xedit execution and run a saved search to look for items inactivated in the last 1 minute. Not sure if it'll work but give it a shot.
w
One issue I see is that you didn't define
'N/log'
, but you're trying to use it. I'm not sure though if that causes the script to fail and exit early. I'm still pretty new with SuiteScript 2.0 scripts.
j
@Will we don't need to define log module, it works on my other userevent script
w
Is that another userevent script for the same page?
j
yes I have other userEvent script that checks for customer, inventory item and contact edit action.