Hello, how do I get the information from the invoi...
# suitescript
s
Hello, how do I get the information from the invoice NO. field to the MEMO? For example, text from the invoice NO. field appears in the MEMO field.
c
Do you know any suitescript? (Just asking that, as it is a trivial thing to do)
s
@CD Some other script you say?
I tried using getText but it doesn't seem to work
Copy code
function createNote(installment, recordId, userId, error, occurrence) {
            var title = '';
            var memo = '';
            var transaction = record.load({ type: record.Type.INVOICE, id: id, isDynamic: true });
            var tranid = transaction.getText({ fieldId: 'tranid' }); //peguei o valor de tranid

            if (error) {
                if (installment) {
                    title = 'Parcela ' + installment.id;
                    memo = 'Parcela ' + installment.id + ' - Transação ' + installment.transaction + 'n° Fatura: ' + tranid + ' - Erro: ' + error.error;
                } else {
                    title = 'Parcela não identificada';
                    memo = 'Erro antes de identificar a parcela - Linha do arquivo: ' + error.line + 'n° Fatura: ' + tranid + ' - Erro: ' + error.error;
                }
            } else {
                title = 'Parcela ' + installment.id;
                memo = 'Parcela ' + installment.id + ' - Transação ' + installment.transaction + 'n° Fatura: ' + tranid + ' - Parcela processada com sucesso - Ocorrência ' + occurrence.name;
            }

            var note = record.create({ type: 'note', isDynamic: true });
            note.setValue({ fieldId: 'recordtype', value: getRecordTypeId(), ignoreFieldChange: true });
            note.setValue({ fieldId: 'record', value: recordId, ignoreFieldChange: true });
            note.setValue({ fieldId: 'title', value: title, ignoreFieldChange: true });
            note.setValue({ fieldId: 'note', value: memo, ignoreFieldChange: true });
            note.setValue({ fieldId: 'author', value: userId, ignoreFieldChange: true });
            note.save();
        }
@CD I created these two variables, to access the invoice and to get the text from the field
var transaction = record.load({ type: record.Type.INVOICE, id: id, isDynamic: true });
var tranid = transaction.getText({ fieldId: 'tranid' });
z
Did you try
var tranid = transaction.getValue({ fieldId: 'tranid' });
as well?
s
@Zack Yes, but the value of this field is string
z
getValue still pulls strings when they are not list type fields. getValue vs getText more matters on list type fields were getValue will get the internalId while getText will return the text value in the list.
s
hey @Zack I tried doing it this way, but it doesn't work. The field value does not appear in the memo The way to get the field value would be this, correct? I've tried this in other scripts, but this time, it doesn't seem to work.
Copy code
function createNote( installment, recordId, userId, error, occurrence, context )
     {
         var title = '';
         var memo = '';
         var rec = context.newRecord;
         var transRec = record.load({type: rec.type, id: rec.id});
         var tranid = transRec.getText({field: 'tranid'});

         if( error ) {
             if (installment) {
                 title = 'Parcela ' + installment.id;
                 memo = 'Parcela ' + installment.id + ' - Transação ' + installment.transaction + ' - n° Fatura: ' + tranid + ' - Erro:' + error.error;
             } else {
                 title = 'Parcela não identificada';
                 memo = 'Erro antes de identificar a parcela - Linha do arquivo: ' + error.line + ' -  n° Fatura: '+ tranid +' - Erro: ' + error.error;
             }
         } else {
             title = 'Parcela '+installment.id;
             memo = 'Parcela '+installment.id+' - Transação '+ installment.transaction+' - Parcela processada com sucesso - Ocorrência '+ occurrence.name;
         }

         var note = record.create({ type: 'note', isDynamic: true });
         note.setValue({ fieldId: 'recordtype', value: getRecordTypeId(), ignoreFieldChange: true });
         note.setValue({ fieldId: 'record', value: recordId, ignoreFieldChange: true });
         note.setValue({ fieldId: 'title', value: title, ignoreFieldChange: true });
         note.setValue({ fieldId: 'note', value: memo, ignoreFieldChange: true });
         note.setValue({ fieldId: 'author', value: userId, ignoreFieldChange: true });
         note.save();
     }
z
Copy code
function createNote( installment, recordId, userId, error, occurrence, context )
     {
         var title = '';
         var memo = '';
         var rec = context.newRecord;
         var transRec = record.load({type: rec.type, id: rec.id});
         var tranid = transRec.getValue({field: 'tranid'});
//CHANGED THIS ^
         if( error ) {
             if (installment) {
                 title = 'Parcela ' + installment.id;
                 memo = 'Parcela ' + installment.id + ' - Transação ' + installment.transaction + ' - n° Fatura: ' + tranid + ' - Erro:' + error.error;
             } else {
                 title = 'Parcela não identificada';
                 memo = 'Erro antes de identificar a parcela - Linha do arquivo: ' + error.line + ' -  n° Fatura: '+ tranid +' - Erro: ' + error.error;
             }
         } else {
             title = 'Parcela '+installment.id;
             memo = 'Parcela '+installment.id+' - Transação '+ installment.transaction+' - Parcela processada com sucesso - Ocorrência '+ occurrence.name;
         }

         var note = record.create({ type: 'note', isDynamic: true });
         note.setValue({ fieldId: 'recordtype', value: getRecordTypeId(), ignoreFieldChange: true });
         note.setValue({ fieldId: 'record', value: recordId, ignoreFieldChange: true });
         note.setValue({ fieldId: 'title', value: title, ignoreFieldChange: true });
         note.setValue({ fieldId: 'note', value: memo, ignoreFieldChange: true });
         note.setValue({ fieldId: 'author', value: userId, ignoreFieldChange: true });
         note.save();
     }
😄 1
Can you log the tranid and see if it is actually being set on that variable?
s
When you post script snippets, it would be more helpful to only post the relevant parts rather than the whole script.
s
Sorry @Zack, I did not understand. How I do ?
n
You only set the memo variable with the tranid if you go in to the if(error) block, is it going in to this code? The else block does not contain tranid. Could that be your issue?
s
Hi, @NElliott Should I create an else block with tranid? This message that I'm concatenating, should appear regardless of the error or not. So I created this variable 'tranid' because the name of the id of the field is tranid. I tried to use search.lookUpFields, because this field is in the invoice body
n
@Slig I've DM'd you, I think you are getting confused. I'm about to log for the day though, so you many need to try catching up with me tomorrow.