I know nothing about suitescript (sorry) but this ...
# suitescript
d
I know nothing about suitescript (sorry) but this sample code is what I need on the custom form level. I just want to prevent deleting lines on approved purchased orders while still allowing all other changes to the sublist. I thought to attach the script to the form and a wf to change to the form when PO conditions are in an approval state. I seem to be missing something though. Because this doesn't work. Am I supposed to update a variable or something? 😓
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */

define(['N/record'],function(record) {‌
	//validateDelete
	function validateDelete(scriptContext) {‌
		alert('validateDelete: cannot delete the current line')
		return false;
	}

	return {‌
		validateDelete: validateDelete
	};
});
n
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 */

define(["N/record"], function(record) {

  function validateDelete(scriptContext) {
    // get your current record object
    const {currentRecord} = scriptContext;

    // get the approval status of the PO. 2 = Approved
    const approvalStatus = currentRecord.getValue({fieldId: 'approvalstatus'})

    // if the approval status is 2, then the PO is approved and the line cannot be deleted
    if (approvalStatus === '2') {
      alert("validateDelete: cannot delete the current line");
      return false;
    }

    // if the approval status is not 2, then the PO is not approved and the line can be deleted
    return true;
  }

  return {
    validateDelete: validateDelete
  };
});
Real close. You just have to get the approval status and set an if statement to return false if the PO is approved.
Let me see if i can get you instructions to deploy it real quick
d
okay cool i was looking at other examples of this script use and yeah i thought i might be missing defining the recorrd and such
I know how to deploy i think. I was just going to attach it to the form
n
Ok cool. If for some reason attaching it to the form doesnt work, you can just deploy it like this https://app.tango.us/app/workflow/Deploying-Client-Script-To-PO-0031fd8fe3514e9383d21d7a1f5b86e0
❤️ 1
If you follow that path though, just beware that setting it to released will deploy it for everyone. If you want to test it first, leave the status of the script deployment in testing and it will only run for you
👍🏼 1
d
Delightful, it works so well
🎉 1
🚀 1