This topic contains 6 replies, has 2 voices, and was last updated by  Casey Trauer 1 month, 1 week ago.

How to validate the fields

  • Hi,

    I am trying to do validations on individual fields, say for example in the below XML

    <rosters>
    <roster>
    <id> 135 </id>
    <employee-code>8015849</employee-code>
    <roster-date>2018-09-03</roster-date>
    <workspace-code>W45</workspace-code>
    <shift-code>DO</shift-code>
    <start-time>0700</start-time>
    <end-time>1600</end-time>
    <break-duration>60</break-duration>
    </roster>
    <roster>
    <id> </id>
    <employee-code>WES1566</employee-code>
    <roster-date>2012-12-03</roster-date>
    <workspace-code>MSL</workspace-code>
    <shift-code>N_SHFT</shift-code>
    <start-time>1900</start-time>
    <end-time>2300</end-time>
    <break-duration>30</break-duration>
    </roster>
    </rosters>

    1. If any one element is null, I should report it as error(handling null values)
    2. Check the range of ID say between 100 to 999 (can accept 3 digits)
    3. Convert date format from source to the one available in destination
    4.the start time must be less than end time

    How can I achieve this?

    I couldn’t find any documentations related to it. If any one could redirect, it will be more helpful.

    Hi Casey,

    Can you help me figure this out. I am trying to use validate.lua to modify to my requirements. But while checking the RequiredField, I am unable to get the nodevalue say rosters.roster.id. It is throwing an error “attempt to call method ‘nodetext’ (a nil value)”.

    Hello,

    Here is some sample code that may illustrate the logic that you need based on the xml snippet you provided. (Of course, it can be executed much more elegantly in discrete functions.)

    function main(Data)
    local xml = xml.parse{data=Data}

    for i=1, xml.rosters:childCount("roster") do

    -- Check for existing of node
    if (xml.rosters:child("roster", i).id) then

    local id = xml.rosters:child("roster", i).id:nodeText()

    -- Check for empty node
    if id == '' then
    trace("This node is empty. You may have to strip spaces to get test to work.")

    elseif tonumber(id) < 100 then trace("id too low") elseif tonumber(id) > 999 then
    trace("id too high")
    end

    end

    end

    end

    The validate.lua module that you referred to is designed mainly for HL7 messages, not xml. But you could still likely adapt the techniques.

    For formatting dates and time comparisons, check out this help page as well as the datetime parser module in the built-in repositories.

    Casey Trauer,
    Director, Client Education
    iNTERFACEWARE

    I have achieved the above validations and made some transformations. Can we perform these validations and transformations in source or do we need to perform inside filter component?

    If we can perform in filter component, do I need to send the parsed XML data from source to filter via queue.push ?

    If no, what operations can be performed in filter?

    It depends.

    How are you receiving the data? What is your source component? Some components do not rely on scripts, so you would not use queue.push in those cases.

    What do you want to happen if a field is found not valid? Do you need to notify the sender that the message does not conform?

    Casey Trauer,
    Director, Client Education
    iNTERFACEWARE

    My source component is from HTTPS.

    I am receiving data from a webservice, validate it and map it to a standard template. And send the mapped data to another webservice at our end.
    On validating, I am sending a response back to the sender saying the field ‘id/workspace’ is null.

    So if the source component is a LLP Listener or From file, I need to use filter. Does that make sense. Correct me if I am wrong.

    If you are receiving data in From HTTPS, you can send validation information back in a HTTP response, which it looks like you are doing. Where you do the other logic probably depends on whether the system that made the requests needs a synchronous result set. Otherwise, you can do you validation and then pass the message to the queue for transformation in another component or channel.

    If you are receiving data From LLP, you can create a custom ACK in the From LLP component. Once you have configured the LLP configurations to use a custom ACK, you will gain access to the Translator, where you can validate the message and build your ACK. Your script here will not actually process the message (i.e. send it to other components). All you are doing here is evaluating the message to see if it conforms.

    From File has no such place to do this. It is common in some integration workflows (X12/EDI) that acknowledgements are written to a folder. Since it is an asynchronous acknowledgement, that can be done in any component.

    Casey Trauer,
    Director, Client Education
    iNTERFACEWARE

You must be logged in to reply to this topic.