RE: Custom item record checkbox that generates message when not true

Hello, My name is Ryan and I am STRUGGLING to generate a message from a checkbox using suite script.

My goal is to inform my team that when an item is ordered on a sales order the suitescript checks to see if the check box is checked. if not,  the alert states “First Article is not approved”.

below is the best I have been able to come up with as the “currentRecord. getcurrentRecordSublistValue” never seems to work. I always run into an issue trying different things.

I dont know how to tell if this would be suited for a UserEventScript or Client Script.

<script>
function validate() {

if (document.getElementById(“FirstArticleCheckBox”).checked == false) {
alert (“First Article is not Approved”);
}
}
</script>

iTriage Rookie Asked on June 3, 2020 in SuiteScript.
Add Comment
1 Answers

The normal way to accomplish this is to add a Custom Transaction Line Field or a Custom Transaction Body Field to your sales order. Make sure to choose an appropiate id for your field, its what you will be using in suitescript.

Then add a Client Script to your sales order that implements either the validateLine or saveRecord (or possibly validateField) entrypoint. The entrypoints run at different times, choose whichever one best matches your needs. Each of the entrypoints has a context object as a parameter which provides information on what is being validated. Importantly, there is a currentRecord.CurrentRecord which is the object that has methods like CurrentRecord.getValue or CurrentRecord.getCurrentSublistValue.

As an example, if you had a transaction body checkbox with the id custbody_first_article and you wanted to validate when the save button was pressed, your code could look like:

/**
* @NAPiVersion 2.0
* @NScriptType ClientScript
*/
define([], function () {
return {
  saveRecord: function (scriptContext) {
   if (
    !scriptContext.currentRecord.getValue({
     fieldId: "custbody_first_article",
    })
   ) {
    alert("First Article is not Approved");
    return false;
   }
   return true;
  },
};
});

Be sure to always return a boolean in these validation type entrypoints.

Intermediate Answered on June 3, 2020.

Thank you very much for taking the time to look at this!  However, I am running into the same situations where nothing happens.  I changed the following…

saveRecord:   to   validateField:

"custbody_first_article" to “custcol_first_article_approved_so” (this is a custom transaction line field)

 

Similar to how Netsuite will send an alert regarding availability when adding a new line to a sales order, I am looking to do the same when First Article Checkbox is false.

RE: Custom item record checkbox that generates message when not true

RE: Custom item record checkbox that generates message when not true

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* @NAPiVersion 2.0
* @NScriptType ClientScript
*/
define([], function () {
return {
  validateField: function (scriptContext) {
   if (
    !scriptContext.currentRecord.getValue({
     fieldId: "custcol_first_article_approved_so",
    })
   ) {
    alert("First Article is not Approved");
    return false;
   }
   return true;
  },
};
});
on June 3, 2020.

You would need to change a lot more of the code if you want to make a validateField entry point function work.

The validateField entry point triggers whenever someone tries to set a field, so you need to choose which field you want to trigger the code off of, and add logic to only trigger whenever the fieldId from the scriptContext is that field.

Secondly, you should use CurrentRecord.getCurrentSublistValue to get the value of a sublist field. CurrentRecord.getValue is for body fields. If for whatever reason you want to get the value of a line that isn’t the current line, then you use CurrentRecord.getSublistValue.

Go through the documentation, or at least experiment with the different entry points to see when they trigger. The validateField entry point would not be my first choice.

You probably also want to share how you setup your client script. The code you shared should have made the form unusable. No body level field would have the id custcol_first_article_approved_so, so the call to getValue should always return an empty string, which should lead to an alert being shown whenever any field is changed.

on June 3, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.