Hi guys, I would like to set a line item field as ...
# suitescript
d
Hi guys, I would like to set a line item field as mandatory if a specific GL account is selected. From what I've seen in SuiteAnswers, this is only achievable using scripts and I am no developer 😅. Is there anyone who has done something similar and is willing to share the script for it so I can tinker with it? If there is a way to do it without scripts, that would be great too
n
Well, Script is your best bet, for normal body field, I would have recommended a WorkFlow, but line level! you need a script . I don't seem to recollect if I have a something similar, but in S/A you can find pretty good and explanatory examples.
k
Use Field changed client script
d
Right. So this is the code that I took from SA ID 49561: Setting Line Item Columns to Mandatory and Autopopulating After Choosing Specific Accounts via Client Script I modded some part of it but I know it definitely is not working because I don't know how to code it so that the account selected is equals to 'account A' in "function clientFieldChanged". Can someone look through it and point out how to correct/improve on this?
Copy code
function clientFieldChanged(type, name, linenum){
 if(type == 'line'){ //checks if the field changed is under sublist 'Lines'
  if(name == 'account'){ //checks if the field changed is 'Account'
   var account = nlapiGetCurrentLineItemValue('line', 'account');
   var index = nlapiGetCurrentLineItemIndex('line');
  }
 }
}

function clientValidateLine(type){
 var currAccount = nlapiGetCurrentLineItemValue('line', 'account');
 var boolComplete = true;
 var i = 0;
 var fieldName = ['2271']; //internalid of fields that will be mandatory
 if(currAccount == '115'){ //checking if account selected is one of the certain accounts
   while (i < fieldName.length && boolComplete == true){ //iterate through each required field
    if(nlapiGetCurrentLineItemValue('line', fieldName[i]) == ''){ //check if customer left the required field blank when adding line item
     alert(fieldName[i] + ' field for \'' + nlapiLookupField('account', currAccount, 'name') + '\' account must be filled in.');
     boolComplete = false; //set to false so the user cannot add the line item
   }
   i++;
  }
 }
    return boolComplete;
}