Announcement

Collapse
No announcement yet.

Converting a flat file to X12 834

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting a flat file to X12 834

    I am trying to convert a flat file to X12 834. When I am using the following code for a particular segment-

    //Creating NM1 segment L2000

    var nm01='IL';
    var nm02='1';
    var nm03=demoString.substring(76,111).trimRight();
    var nm04=demoString.substring(111,126).trimRight();
    var nm05=demoString.substring(126,127).trimRight();
    var nm06=demoString.substring(127,137).trimRight();
    var nm07='';
    var nm08='';
    var nm09=demoString.substring(137,146).trimRight();
    var nm10='';
    var nm11='';
    var nm12='';

    segment=createNM1Segment(nm01,nm02,nm03,nm04,nm05, nm06,nm07,nm08,nm09,nm10,nm11,nm12);
    tmp.appendChild(segment);

    I am getting the following output-
    NM1*IL*1*MUS*SHEL*~

    But the expected output is -
    NM1*IL*1*MUS*SHEL~

    The code for function createNM1Segment is-

    function createNM1Segment(nm101,nm102,nm103,nm104,nm105,nm1 06,nm107,nm108,nm109,nm110,nm111,nm112) {

    var NM1Segment= createSegment('NM1');

    NM1Segment['NM1.01']['NM1.01.1']=nm101;
    NM1Segment['NM1.02']['NM1.02.1']=nm102;
    NM1Segment['NM1.03']['NM1.03.1']=nm103;
    NM1Segment['NM1.04']['NM1.04.1']=nm104;
    NM1Segment['NM1.05']['NM1.05.1']=nm105;

    if (nm106.toString()!='')
    {
    NM1Segment['NM1.06']['NM1.06.1']=nm106;
    }

    if (nm107.toString()!='')
    {
    NM1Segment['NM1.07']['NM1.07.1']=nm107;
    }

    if (nm108.toString()!=''&nm109.toString()!='')
    {
    NM1Segment['NM1.08']['NM1.08.1']=nm108;
    NM1Segment['NM1.09']['NM1.09.1']=nm109;
    }

    if (nm110.toString()!=''&nm111.toString()!='' &nm112.toString()!='')
    {
    NM1Segment['NM1.10']['NM1.10.1']=nm110;
    NM1Segment['NM1.11']['NM1.11.1']=nm111;
    NM1Segment['NM1.12']['NM1.12.1']=nm112;
    }

    return NM1Segment;

    }

    I understand why the problem exists here but how can I resolve this

  • #2
    In your createNM1Segment function you are setting NM1Segment['NM1.05']['NM1.05.1'] = nm105; even when nm105 is an empty string, so it is putting the extra delimiter at the end.

    Comment


    • #3
      Thank you for the response. I understand the problem but how can i resolve this. Should I create an if condition for NM105 as well like NM106 and NM107 ?

      Comment

      Working...
      X