I suppose you have to do a check if 'loc' exists..
if not loc then
before doing your mapping
What is line 46? I suspect this is
If location is missing you obviously need to put this logger into the above for loop...
Also you mapping block is strangely talking about Host mapping but the pattern name refers to Printer...
And you map "on" Host and not "from" Host like an extension would do...
I copied the wrong part of code. Sorry
Here the code for the printer :
In the meanwhile, I've included my loop in a IF block.
I don't get the "subgraph" error anymore, but I get errors :
'loc' not set
It seems that testing the loc value is not enougth.
mapping on Printer as printer_node
printer_ci -> BMC_Printer;
traverse ElementInLocation:Location:Location:Location as loc
log.info("Map printer %printer_node.name%");
loca := "";
if loc then
for each loc do
loca := loc.name;
log.info("loca : %loca%");
If you copy only a portion of the error and a portion of you pattern, without telling what is the line of your pattern that the discovery is complaining about it is very difficult to help.
"if loc then" is the problem and is useless because you have the for block.
As I wrote it but not clearly enough, here you want to create an extension of the Printer syncmapping (read Syncmapping block - Documentation for BMC Discovery 11.3 - BMC Documentation) so mapping from not mapping on.
There is already a very good example of what you are trying to do in Extending the CDM mapping - Documentation for BMC Discovery 11.3 - BMC Documentation
In fact I'm using the predefined Printer Sync script.
I've just put the line I've added into the script.
I use the mapping instruction as it is in the original script. Does it mean I've to modify it if I want to use a traverse in the mapping section?
The error 'loc' not set is pointing the line " if loc then"
But without the "if" test, I get the error 'loc' is not a valid subgraph at this point when the location is not present in the item.
I've already read the doc about the traverse instruction and about retrieving the location. But, I (the customer) don't want to have the location as relationship but as an attribute. My request is related to my previous topic Location name as attribute in ComputerSystem
Sorry for my questions but I'm not used with Discovery scripting (I'm more CMDB Admin).
1 of 1 people found this helpful
You should not be using the existing CMDB.Printer_Printer sync mapping module. You need to write an extension.
mapping from Printer_Printer.printer_node as printer_node
traverse ElementInLocation:Location:Location:Location as location
ci_printer := Printer_Printer.printer_ci;
for each location do
ci_rinter.<attribute> := location.name;
where <attribute> is your attribute name.
But this is not very helpfull as I'll be still facing the situation were a location may not exist.
What is returned if a traverse find nothing?
No you shouldn't! The "for each" loop is handling this.