Not a tech guy here. Hopefully someone can explain...
# suitescript
l
Not a tech guy here. Hopefully someone can explain the relevance of the switch case code here. Code in the reply section. Does it set the value or what? Specifically, the parts where it says CASE 'Bill' : transtype = record.type.VENDOR.BILL
Copy code
function saveRecord(context) {var rec = context.currentRecord
var rejId = rec.id
var rejector = rec.getValue({ fieldId: REJECTOR })
        var tranId = rec.getValue({ fieldId: TRANSACTION })
        var tranType = rec.getText({ fieldId: TRANSACTION}).split(' ')[0];
console.log('tranType = ' + tranType)
Copy code
switch(tranType){
 case 'Bill':
                
tranType = record.Type.VENDOR_BILL;
                break;
            
case 'Journal':
                
tranType = record.Type.JOURNAL_ENTRY;
                break;
            
case 'Invoice':
               
 tranType = record.Type.INVOICE;
                
break;
            
case 'Vendor':
              
 tranType = record.Type.VENDOR_PREPAYMENT;
                break;
            
case 'Credit':
                
tranType = record.Type.CREDIT_MEMO;
                break;}
var reason = rec.getValue({ fieldId: REASON })
a
There's a bunch of stuff in CAPS that doesn't make any sense... the field id: SOMETHINGINCAPS makes little sense without some more context? what it appears to be doing is trying to infer the transaction type based on the.. transaction name? or docid or something? and then its not actually DOING anything with that information, at least in the code you've shared
to answer your question, YES it is setting the value of the variable
tranType
to the correct string from the record.Type enum
its re-using the
tranType
variable. first it uses it to hold the value from rec.getText and then based on the first word in that, it will get the correct string for the transaction type
l
Ohh thank you. It does set the value then.
Is there a more straightforward way to determine the transtype? If I'm only picking the first word, it would not work for VENDOR return authorization and VENDOR prepayment. I can add more if statements but maybe there's a more proper way to do it.
a
yes there's a proper way to do it, not on my work computer right now, but you should just be able to get the type from the context.currentRecord
l
Hi Anthony, sorry for asking again, when you get a chance, could you please share how it should be done correctly? Thank you.
👍 1