RITM Variables such a Number, date along with MRV line items written to a Custom Table

Peter Williams
Kilo Sage

Good Morning everyone,

i have an unusual problem, i need a way  when users submit a request (RITM) to have those variable vaules along with the MRV variable values to be written to a custom table in servicenow.

 

Ex.

User submits an RITM

 

Form variables: 

Number

Name

Date

Office

 

Form MRV Values:

Invoice #

Type

Amount

Details

 

how it should look in the custom table

The RITM variables will be the same but as each MRV value is entered for the RITM it will change

 

NumberNameDateOfficeInvoice#TypeAmountDetails
RITM0001121Peter13-May-24Toronto12345-32Airfare123.02to the office
RITM0001121Peter13-May-24Toronto6587-AVTaxi25.25From the airport
RITM0001121Peter13-May-24Torontotry-432Meal78.41Dinner
6 REPLIES 6

Vengadesh
Tera Guru

Hi @Peter Williams ,

 

Are you utilizing Flow designer or a script to achieve this?

If its via script , Kindly share a script 

i was thinking of a BR to perform this and i have this so far but doesnt seem to work

(function executeRule(current, previous /*null when async*/) {
    // Check if the catalog item is submitted
    if (current.operation() == 'insert') {
        // Retrieve the MRVS values
        var mrvOffice = current.variables.bill_to_office_mrv;
        var mrvClient = current.variables.disbursements_client;

        // Iterate through the MRVS values
        mrvOffice.forEach(function(mrv) {
            // Create a new record in the custom table
            var customRecord = new GlideRecord('u_testing_mrv_upload');
            customRecord.initialize();
 
            // Set MRVS values
            customRecord.setValue('u_amount', mrv.amount_office);
            customRecord.setValue('u_department_invoice', mrv.department_office);
            customRecord.setValue('u_gl_code', mrv.gl_code_office);
            customRecord.setValue('u_invoice_date', mrv.date_office);
            customRecord.setValue('u_invoice_number', mrv.invoice_office);
            customRecord.setValue('u_description', mrv.description_office);
            // Set other fields from the catalog item form
   
            customRecord.setValue('u_number', current.number);
            customRecord.setValue('u_item', current.name);
            customRecord.setValue('u_office_billing', current.variables.office_send_to);
            customRecord.setValue('u_bill_to_office', current.variables.bill_to_office);
            customRecord.setValue('u_bill_to_client', current.variables.bill_to_clients);
            customRecord.setValue('u_total_amount', current.variables.grand_total);
            customRecord.setValue('u_pay_to_the_order_of', current.variables.pay_to_the_order_of);
            customRecord.setValue('u_payment_method', current.variables.payment_method);
            customRecord.setValue('u_requested_for', current.variables.requested_for);
            customRecord.setValue('u_currency', current.variables.currency);
            customRecord.setValue('sys_id', current.sys_id);
            customRecord.setValue('sys_created_on', current.created_on);
            customRecord.setValue('sys_created_by', current.opened_by);
            customRecord.setValue('u_department', current.variables.department);
            // Add more variables as needed
       
            // Insert the record
            customRecord.insert();

        });

         mrvClient.forEach(function(mrvs) {
            // Create a new record in the custom table
            var customRecord = new GlideRecord('u_testing_mrv_upload');
            customRecord.initialize();
           
            // Set MRVS values
            customRecord.setValue('u_amount', mrvs.amount_client);
            customRecord.setValue('u_department_invoice', mrvs.department_client);
            customRecord.setValue('u_file_number', mrvs.file_n);
            customRecord.setValue('u_invoice_date', mrvs.date_client);
            customRecord.setValue('u_invoice_number', mrvs.invoice_client);
            customRecord.setValue('u_description', mrvs.description_client);
            // Set other fields from the catalog item form
            customRecord.setValue('u_number', current.number);
            customRecord.setValue('u_item', current.name);
            customRecord.setValue('u_office_billing', current.variables.office_send_to);
            customRecord.setValue('u_bill_to_office', current.variables.bill_to_office);
            customRecord.setValue('u_bill_to_client', current.variables.bill_to_clients);
            customRecord.setValue('u_total_amount', current.variables.grand_total);
            customRecord.setValue('u_pay_to_the_order_of', current.variables.pay_to_the_order_of);
            customRecord.setValue('u_payment_method', current.variables.payment_method);
            customRecord.setValue('u_requested_for', current.variables.requested_for);
            customRecord.setValue('u_currency', current.variables.currency);
            customRecord.setValue('sys_id', current.sys_id);
            customRecord.setValue('sys_created_on', current.created_on);
            customRecord.setValue('sys_created_by', current.opened_by);
            customRecord.setValue('u_department', current.variables.department);
            // Add more variables as needed
           
            // Insert the record
            customRecord.insert();
        });
    }
})(current, previous);
 
what do you think is the best approach

Hi @Peter Williams ,

 

Better you can try with flow designer, I have tried once as like your requirement 

Simply you can utilize "Get catalog variables and Create record "actions to create a record in the custom table

For MRVS scenario you can directly drag and drop the pills to set the values

If you need further assistance , kindly reach me 

 

If it works for you, mark mine as accepted

Regards

Vengadesh

i did it but nothing happens

 

 

PeterWilliams_0-1715613256254.png

 

 

PeterWilliams_1-1715613330041.png