Solution for showing Original Bill Number and Memo in Billable Expenses sublist of Invoice Record.

Create a transaction line field named ‘Original Expense’ and a ‘Memo’ field in the bill record. Utilizing a userevent script in the afterSubmit event, we can assign the transaction number of the bill record to the ‘Original bill number’ field and simultaneously transfer the value from the standard memo field in the ‘Expense’ subtab to a custom memo field. The values in these custom fields will be automatically populated into the ‘Billable Expenses’ sublist of the Invoice Record.

User Event Script:

const afterSubmit = (scriptContext) => {

      try {

        let newRecord = scriptContext.newRecord;

        let subsidiary = newRecord.getValue({

          fieldId: ‘subsidiary’

        })

         //Added subsidiary restrictions: script will work for steritek subsidiaries only.

        if ((subsidiary == ‘5’ || subsidiary == ‘4’ || subsidiary == ‘1’) && (scriptContext.type === scriptContext.UserEventType.CREATE || scriptContext.type === scriptContext.UserEventType.EDIT)) {

          let recObject = record.load({

            type: ‘vendorbill’,

            id: newRecord.id

          })

          let expenseSublistId = ‘expense’;

          let lineCount = recObject.getLineCount({

            sublistId: expenseSublistId

          });

          let billNumber = ‘custcol_jj_st_bill_number’;

          let standardMemo = ‘memo’;

          let customMemo = ‘custcol_jj_st_memo’

          let transactionNumber = recObject.getValue({

            fieldId: ‘transactionnumber’

          });

          for (let line = 0; line < lineCount; line++) {

            // Set the transaction number to the custom line field on each line of the Expense subtab

            recObject.setSublistValue({

              sublistId: expenseSublistId,

              fieldId: billNumber,

              line: line,

              value: transactionNumber

            });

            var memo = recObject.getSublistValue({

              sublistId: expenseSublistId,

              fieldId: standardMemo,

              line: line

            });

            if (memo) {

              recObject.setSublistValue({

                sublistId: expenseSublistId,

                fieldId: customMemo,

                line: line,

                value: memo

              });

            }

          }

          recObject.save({

            ignoreMandatoryFields: true,

            enableSourcing: true

          })

        }

      } catch (e) {

        log.error(“error in after submit function”, e)

      }

    }

    return { afterSubmit }

  });

Leave a comment

Your email address will not be published. Required fields are marked *