Announcement

Collapse
No announcement yet.

setName method works only for some segments

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

  • setName method works only for some segments

    I've been working on this for a while. Please... I hope someone can help. I have no idea why the setName method works with some nodes and not with other. My Code Template is supposed to check if the node exists (can someone verify that's the way to do so?). Because I noticed before that setName would not work if the referenced node didn't exist in msg.

    DETAILS:
    TypeError: setName is not a function, it is xml. (com.mirth.connect.server.MirthJavascriptTransform erException)

    I am using this method in Code Template:
    Code:
    function renameSegment(segment, newName) {
    	// write code here.
    	if (segment != null) {
    		segment.setName(newName);
    	};
    };
    Calling Transformer step:
    Code:
    renameSegment(msg['NTE']['NTE.1'], 'NTE_1_SetIdNotesAndComments');
    renameSegment(msg['NTE']['NTE.2'], 'NTE_2_SourceOfComment');
    renameSegment(msg['NTE']['NTE.3'], 'NTE_3_Comment');
    renameSegment(msg['NTE'], 'NTE_NotesAndCommentsSegment');
    Mirth Connect Administrator 2.0.0.5127
    Built on October 28, 2010

  • #2
    not sure what the problem is here but I would guess you would run into issues if you had multiple NTE segments in your message.
    Daniel Svanstedt
    Software Engineer
    Mirth Corporation

    Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
    Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

    Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

    Comment


    • #3
      Daniel...

      Yes. You're right Indeed I have several NTE Segments. That explains why it does not happen when I run it on the PID segment. Do you know a way I could accomplish the conversion? I don't need to differentiate the several NTE's or OBX's. I just need them to have the name that matches my application. (All NTE's must be named NTE_NotesAndCommentsSegment... All NTE.1, NTE_1_SetIdNotesAndComments... and so on).

      Thanks.

      Comment


      • #4
        "Several NTE Segments" was the problem.

        Thanks Daniel.

        It was the cause (Several NTE's)... I finally got it to work using:
        Code:
        for each (seg in msg['NTE']) {
        	renameSegment(seg['NTE.1'], 'NTE_1_SetIdNotesAndComments');
        	renameSegment(seg['NTE.2'], 'NTE_2_SourceOfComment');
        	renameSegment(seg['NTE.3'], 'NTE_3_Comment');
        	renameSegment(seg, 'NTE_NotesAndCommentsSegment');
        };
        Now it does not give the error and actually gives me the result I need.

        It has to go in the Destination Transformer, too (I had it in the Source Transformer before)

        The Code Template is like (Notice the condition is different changed segment != null to segment. length() > 0):
        Code:
        function renameSegment(segment, newName) {
        	// write code here.
        	if (segment.length() > 0) {
        		segment.setName(newName);
        	};
        Last edited by eramirez; 03-31-2011, 08:38 AM.

        Comment

        Working...
        X