Is it possible to create a closed button on estima...
# suitescript
k
Is it possible to create a closed button on estimates that triggers a status change to “closed”?
l
try,
Copy code
/**
 * This function is triggered when the "Closed Lost" button is clicked.
 * It sets the estimate status to "Closed".
 */
function closedLostButtonFunction() {
  // Set the estimate status to "Closed"
  nlapiSetFieldValue('status', 'Closed');

  // Save the record
  nlapiSubmitRecord(nlapiGetRecord());
}

/**
 * This function adds the "Closed Lost" button to the Estimate form.
 */
function addButtonToEstimateForm() {
  // Create a new button object
  var closedLostButton = form.addButton('custpage_closed_lost_button', 'Closed Lost', 'closedLostButtonFunction');

  // Set additional properties of the button if needed
  closedLostButton.setLayoutType('outsidebelow');
  closedLostButton.setDisabled(false);
  // Add more customization options as required

  // Save the changes to the form
  form.setScript('closedLostButtonFunction');
}

// Call the function to add the button when the form is loaded
addButtonToEstimateForm();
by chatgpt
🙌 1
b
fairly impressive, only maybe 2 lines (4 if you include the function definitions) out of that script dont have an error or mistake associated with it
🤖 2
😂 2
very low quality response from chatgpt that leo didnt bother reviewing
the basic idea is correct, add a button that edits the estimate, though the code itself is fairly useless
k
@battk any tips on how to write it?
b
first step is to learn how to close the estimate in the ui
then replicate that process using the N/record Module
k
Yeah That’s why I raised the question, because dob’t seem to be able to do it on line level?
b
correct, although learning how to close an estimate isnt really a suitescript question
k
Well just asking in general if it is possible to script the status change on estimate level
b
it sounds more like you either dont know how to close an estimate in the ui, or dont know how to use N/record, or dont know how to make buttons
but if you just wanted an answer to your question, then answer is yes, you can script it
s
You can achieve this through a workflow. Check out suiteanswer 86336
🙏 1