web stats
setName method works only for some segments - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2011, 01:27 PM
eramirez eramirez is offline
Mirth Newb
 
Join Date: Dec 2010
Posts: 11
eramirez is on a distinguished road
Question 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
Reply With Quote
  #2  
Old 03-30-2011, 03:00 PM
dans dans is offline
Mirth Employee
 
Join Date: Apr 2007
Location: Irvine, CA
Posts: 590
dans is an unknown quantity at this point
Default

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!
Reply With Quote
  #3  
Old 03-31-2011, 05:28 AM
eramirez eramirez is offline
Mirth Newb
 
Join Date: Dec 2010
Posts: 11
eramirez is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 03-31-2011, 08:34 AM
eramirez eramirez is offline
Mirth Newb
 
Join Date: Dec 2010
Posts: 11
eramirez is on a distinguished road
Talking "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 at 08:38 AM.
Reply With Quote
Reply

Tags
code template, function, msg, setname, transformer

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 09:56 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation