I have created a custom button on a record using suitescript in userevent, when click that button it calls the client-script then the client-script will run after page will be refreshed. After click button it takes some time to refresh the page at that time button should be disable to avoid multiple clicks.
userevent script:
if(userRole == 3 || prStatus == "Partially Ordered"){
scriptContext.form.addButton({
id: "custpage_fullyorder_button",
label: "Fully Order",
functionName: 'make_PR_FullyOrder'
});
}
client script:
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);
these are tried and commented. is there any jquery code include in suitescript???
Share your code and I can be more specific. Generally to disable a button after it's been pressed once/executed you can do the following.
//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
};
});