Update Metadata Document via Script

I am having trouble solving what appears to be a straightforward issue, and I was wondering if anyone might assist me.
I am trying to update the metadata of datamapper with updated fields from CSV file. CSV field names are similar to datamapper fields. and there have been corrections made to the CSV data. check the script below
sample.txt (1.4 KB)
Here, I want to update the datamapper values by running the js script. For that, I used the Run Script plugin, and after the plugin, I used the Update Data Record task to update all database records with the values stored in the metadata. but for some reason, CSV data is not binding with the correct record/document in DataMapper. I tried applying the condition that compares the ‘accntnmbr’ first in the csv and metadata document; if matching, then update the other fields for that record in the metadata document.

for (i = 1; i < idxField.length; i++) {
  if ( idxNo[i] != -1 ) {
    if (oMetaData.job().group(0).document(src_seq-1).FieldByName('_vger_fld_accntnmbr').toString() == strCSVData[0]) {
      oMetaData.job().group(0).document(src_seq - 1).fields.add2('_vger_fld_' + idxField[i], strCSVData[idxNo[i]], 0);

one records data is updating for another record or so. Is there any mistake in the code?
I have written this code by actually referring to the different forum answers and solutions.
I would appreciate any help on this. Thanks

From what I can tell, your code should be correct, assuming that the CSV contains the proper record number values.

When you say that “one records data is updating for another record or so”, can you determine if there’s a pattern to it? Is the script always updating the next record, or the previous record? Or is it updating some random record?

And where does that CSV come from?

Script updating random records and even updating a few fields in metadata, few fields remain empty.
CSV file is generated for some corrected fields here. It is generated externally.
I tried another way here, sample_2.txt (1.1 KB)
But this also seems to be not working. trying to understand the possible mistake here.

Without having access to your process and to the CSV, it’s almost impossible to tell what’s wrong with your code.

If you can provide a basic process that replicates the issue, using anonymized data, please post it here for further investigation. Otherwise, I recommend you open a ticket with our Support team.