Creé un botón personalizado en un registro usando suitescript en evento de usuario, cuando hago clic en ese botón llama al script del cliente y luego el script del cliente se ejecutará después de que se actualice la página. Después de hacer clic en el botón, se tarda un tiempo en actualizar la página ; en ese momento, el botón debe desactivarse para evitar varios clics.
script de evento de usuario:
if(userRole == 3 || prStatus == "Parcialmente pedido"){
scriptContext.form.addButton({ id: "custpage_fullyorder_button", label: "Fully Order", functionName: 'make_PR_FullyOrder' }); }guión del cliente:
function make_PR_FullyOrder(){ //var sublistFieldName = context.fieldId; if(typeof window != 'undefined' && window.document){ window.document.querySelector('#custpage_button').disabled = true; // id from add button call in user event script } console.log('pr id:'+recordId); var pr_record = record.load({ type:recordType, id: recordId, isDynamic: true }); /* pr_record.setValue({ fieldId:FullyOrderCheckBox, value:true });*/ console.log('pr loaded'); // $("#custpage_fullyorder_button.rndbuttoninpt.bntBgT" ).prop( "disabled", true ); console.log('2'); //$("#custpage_fullyorder_button.rndbuttoninpt.bntBgT").attr("disabled", "disabled"); //document.getElementById("custpage_fullyorder_button.rndbuttoninpt.bntBgT").disabled = true; //document.getElementByName('custpage_fullyorder_button').setAttribute("disabled","disabled"); //closed unlinked po item lins var sublistLineCount = pr_record.getLineCount({sublistId:'item'}); log.debug('item line count:',sublistLineCount); console.log('line count:'+sublistLineCount);estos son probados y comentados. ¿Hay algún código jquery incluido en suitescript?
Comparte tu código y puedo ser más específico. En general, para deshabilitar un botón después de que se haya presionado/ejecutado una vez, puede hacer lo siguiente.
//get the value from the identifying field var identifier = curRec.getValue({fieldId: 'customfieldId'});
//if identifying field is true show the button if (identifier == true){ var customButton = form.addButton({ id : 'custpage_button', label : 'Call Client Script', functionName: 'myLongRunningFunction' }); form.clientScriptModulePath = './longRunningFunction_CS.js'; //if identifying field is false do not show the button/do nothing } else { //do nothing }
longRunningFunction_CS.js
/** * @NApiVersion 2.x * @NScriptType ClientScript */ define(["N/currentRecord"], function (currentRecord){ function myLongRunningFunction(){ if(typeof window != 'undefined' && window.document){ window.document.querySelector('#custpage_button').disabled = true; // id from add button call in user event script } var rec = currentRecord.get(); // do whatever processing... var custRec = record.load({ type: rec.type, id: rec.id }); } return { myLongRunningFunction : myLongRunningFunction }; });