Copying one field into another with a script

Topic Labels: Extensions
699 0
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

Hello, does anyone have a script that can be used to copy one fields data into another? I need to be able to input a search query using something like the updateRecordAsync() code to update one field with another’s data. The issue is, that I need it to rely on a user input, so I want to be able to choose the preset of quantity by having a await input.textAsync(). I would then define the quantity options in different fields, and the input would be that fields name. It would then copy the chosen fields data into the main field. It must also include a way to scan for a specific record to be the one to be updated. I have code written for this already, but it would need integrated into a script for it. This is what I have so far. It lets me scan my product inventory table for specific products, and copy those products all into a my invoice transaction table all under one specific record number. It gets represented by a number that looks like IN-#. This number would need to be used to scan and choose the records that need their quantities changed.
I currently have this code.

//Invoice Transaction From Assembly & Generate Invoice
let inv = base.getTable("Product Inventory");
let transactions = base.getTable('Invoice Transactions'); 
let potemp = await input.textAsync('Enter Temp INV Number');
let dptemp1 = await input.textAsync('Enter Deluxe Package Number');
let potemp1 = Number(potemp);
let dpnum = Number(dptemp1);
let dpfinal = dpnum;
output.text ("Assembly" + dpfinal);
output.text("Creating Invoice transactions...");

//let potemp = 108;
let quantity = 1;

//Part1 - Creates transactions for assembly in Invoice Transaction table
let result = await inv.selectRecordsAsync(
    sorts: [
        // sort by "Notes" in ascending order...

for (let record of result.records.filter( r => r.getCellValue('assembly')))
    	let assembly= record.getCellValue("assembly");
        //if (assembly.startsWith("Deluxe Pack"))
        if (assembly.startsWith(dpfinal))
           await transactions.createRecordAsync( {
          "IN-TEMP" : potemp1,
          "Product Quantity": quantity,
          "Product Inventory": [record],

output.text("Created Invoice Transaction of Assembly for IN - " +potemp1);
output.text("Lets move on and create the invoice!");
output.text("Go into the Assembly Transaction view within the Invoice Transactions table and update the filter to be " +potemp1);
await input.textAsync ("Enter anything when this has been done");

let transactionstable = base.getTable('Invoice Transactions'); 
let Invoices = base.getTable('Invoice');
let AssemblyAdder = transactionstable.getView("Assembly Transactions");

let result1 = await AssemblyAdder.selectRecordsAsync(
    sorts: [
        // sort by "Notes" in ascending order...
        {field: "Item Detail"},      

     let record2 = await Invoices.createRecordAsync( {          
       await Invoices.updateRecordAsync(record2, {
              "PO Line Items": result1.records, 
output.text("Created Invoice in Invoices table");
0 Replies 0