Problems with Eval Javascript in Transform Table Pattern Operation

tphillips
Tera Contributor

I am writing up a horizontal discovery pattern that is bringing back Display (monitor) information.  When I am performing the Transform Table operation, I have one field that takes the Manufacture and should return the Manufacture SysID from the core_company table.  The code below is not returning a proper SysID when I have it in the field as Eval Javascript:

var newVendor = ${displaysMonitor1[].monitorVendor1};

var mm = Packages.com.snc.cmdb.MakeAndModel.fromNames(newVendor , null);
var mfgSysID = mm.getManufacturerSysID();
ms.log("Debug ::" + newVendor+ "::" + mfgSysID);
rtrn = mfgSysID;

 

The vendors being returned are in the core_company table. I am getting no errors from the script. mm and mfgSysID are coming back undefined.

What else can I try?

 

Thanks,

Tom

10 REPLIES 10

Okay is this in a Transform or Set operator? Can you try to add a debug line to output the type of newVendor? You should be able to use typeof to do that. I am wondering if what's being returned since it's in a table and there are more then 1 value (although if you are in a transform operation I believe it should only return a string) it may be returning it as an object instead of a string and this is why the call isn't returning what you expect.

I've had this issue before with evals because the ${} returns things as java arraylists and other types that you have to convert sometime.

This is in a Transform Table operation.  Added the debug and here is a result:

 

09/14/18 07:38:33 (782) Worker-Interactive:PatternDebuggerProbe *** Script: Debug :: typeof newVendor string typeof mm undefined


newVendor is string

mm is Undefined

 

Yeah so it looks like the package is returning null so it may not be available on mid server side. When I get home I'll look st mid server include files to see if it exists. You may need to open a hi ticket. Is there a out of the box pattern that uses this function call? You may want to look at a post processing script to call this package if it isn't available st the mid server level (I would look at using this).

OK. 

 

Let me see what I can do/find out.  Thanks for the suggestions and looking into this.

 

Tom

Yep Pre/Post Processing under pattern designer should do exactly what you want. This way you can just set the value and access it with the Post Processing to actually do the normalization for you. If this works feel free to mark an answer as correct and I wish you the best of luck!