Hi! I am trying to extract the account number from...
# suitescript
b
Hi! I am trying to extract the account number from the account so I can have some code that runs if the account number is between 2000 and 4500 for example. When I use this I just get the full account number and name... what is the best solution for this?
Copy code
let glAccount2 = objRec.getCurrentSublistText({sublistId : sublistID,fieldId: 'account'})
1
As usual, as soon as I post I find a solution. I've used this.. Is there a better way?
Copy code
let glAccount2 = objRec.getCurrentSublistText({sublistId : sublistID,fieldId: 'account'})
let glAccount3 = glAccount2.substring(0, glAccount2.indexOf(' '));
n
if you know it's after the space you could probably do:
Copy code
let glAccount2 = (objRec.getCurrentSublistText({sublistId : sublistID,fieldId: 'account'})).split(' ')[0];
if you get your brackets right
t
@BullgillRunner whats record is objRec?
b
@Timothy Wong
Copy code
let objRec = scriptContext.currentRecord;
Further changes have me getting the result returned as a number...
Copy code
let glAccount3 = Number(glAccount2.substring(0, glAccount2.indexOf(' ')));
t
but what is objRec.type?
journalentry?
b
It's any transaction type. Mainly cash entries but also journals/vendor bills etc.
Copy code
if(objRec.type =='journalentry'){
            sublistID = 'line';
            fieldIdContract = 'entity';
        }
        if(objRec.type == 'check'){
            sublistID = 'expense';
            fieldIdContract = 'customer';
        }
        if(objRec.type == 'vendorbill'){
            sublistID = 'expense';
            fieldIdContract = 'customer';
        }
        if(objRec.type == 'purchaseorder'){
            sublistID = 'expense';
            fieldIdContract = 'entity';
        }
t
i see, not unless you do a custom field for whatever purpose, i think @NElliott is right and that'd be the approach to go with
b
Thanks for the advice... I have got it working as I need using this code...
Copy code
let glAccount2 = objRec.getCurrentSublistText({sublistId : sublistID,fieldId: 'account'})
let glAccount3 = Number(glAccount2.substring(0, glAccount2.indexOf(' ')));
if( glAccount3 >= 4901 & glAccount3 <= 4999 & costCentreField.charAt(0) === '' & subsid == 2){
              dialog.create({title: "⚠ WARNING ⚠", message: '<div style="color:red;font-size:40px;"><center><b>!! WARNING !!</b></center></div><br><div style="color:black; background-color:#E0FFFF; padding:10px; border-radius:10px;font-size:20px;"><b>GL Accounts 4901 - 4999 require a cost centre to be entered.  Please check and correct.</b></div>',
                         buttons: [{ label: 'Close', value: 1 }]
                            });
              return false;
            }
🙌 1