Validating EDI Data – JS

Index

    Validating EDI Data

    EDIValidator allows you to validate EDI data from a string of EDI text using the EDIDataString property. A valid validation rules data is also required. Please see our programming examples.

    Example

    const edi = require(‘rdpcrystal-edi-library’);
     
    //Create a validator instance
    let validator = new edi.EDIValidator();
     
    //Set the validation rules data
    //Validation rules are found in the RDPCrystalInstallation\Validation Rules directory
    validator.EDIRulesFileData = “Add your validation rules data here–see our ‘validatedocument’ programming example”;
     
    //Validate and also load the data into memory
    validator.LoadValidatedData = true;
     
    validator.EDIDataString = “ISA*00*……….*01*SECRET….*ZZ*SUBMITTERS.ID..*ZZ*RECEIVERS.ID…*030101*1253*^*00501*000000905*1*T*:~” +
        “GS*Hk*SENDER CODE*RECEIVERCODE*19991231*0802*1*X*005010X279A1~” +
        “ST*271*1234*005010X279A1~” +
        “BHT*0022*13*10001234*20060501*1319~” +
        “HL*1**20*1~” +
        “NM1*PR*2*ABC COMPANY*****PI*842610001~” +
        “HL*2*1*21*1~” +
        “NM1*1P*2*BONE AND JOINT CLINIC*****SV*2000035~” +
        “HL*3*2*22*0~” +
        “TRN*1*93175-012547*9877281234~” +
        “NM1*IL*1*SMITH*ROBERT****MI*11122333301~” +
        “DMG*D8*19430519~” +
        “DTP*291*D8*20060501~” +
        “EQ*30~” +
        “SE*13*1234~” +
        “GE*1*1~” +
        “IEA*1*000000905~”;
    validator.validate();
     
     
    //Get all errors from the EDI data
    for (let i = 0; i < validator.Errors.Count; i++) {
        let error = validator.Errors.getItem(i);
     
        console.log(
            {
                Type: “Error”,
                Line: error.LineNumber,
                Transaction: “”,
                SnipLevel: error.SnipLevel, //SnipTestLevel Enum
                Message: error.Message,  //EDIValidationMessage Enum
                Loop: error.Loop,
                Segment: error.Segment,
                Element: error.ElementOrdinal,
                Composite: error.CompositeElementOrdinal,
                Description: error.Description,
                Ordinal: error.SegmentOrdinal
            });
    }
    in EDI Validator – JS
    Did this article answer your question?