How to dot walk child table's fields in field map?

Ankita9
Tera Contributor

Hi All,

 

I want to dot walk to map fields of "MS SQL Database" table which is a child table of CMDB CI. 

There are few text fields "Server port, ucmdb model, Maintenance Window Info,  Patch Group, Next refresh" which are child class specific.  I tried using "source script" but no luck. Please suggest.

 

Source Script : target.ref_cmdb_ci_db_mssql_database.tcp_port = source.u_server_port;

 

Ankita9_1-1666254547894.png

 

1 ACCEPTED SOLUTION

Arnaud Derancou
Kilo Guru

Hi,

 

Please try with :

target.sys_class_name = 'cmdb_ci_db_mssql_database';

target.tcp_port = source.u_server_port;

 

I'd expect this to work.

 

if this is not working you can add "On after" script and do a glideRecord on the target table with "target.sys_id" and update the field like this, but that will trigger a second update so option 1 is preferred.

 

var gr=new GlideRecord('cmdb_ci_db_mssql_database');

if (gr.get(target.sys_id)) {

gr.tcp_port = source.u_server_port;

gr.update();

}

 

Regards

Arnaud

View solution in original post

5 REPLIES 5

Arnaud Derancou
Kilo Guru

Hi,

 

If you want to do this I think you need to specify the target class as well:


target.sys_class_name = 'cmdb_ci_db_mssql_database';

and target.cmdb_ci_db_mssql_database.tcp_port = source.u_server_port;   (i've removed the ref_)

 

Regards

Arnaud

Hi Arnuad,

 

Thanks for your response!!
I tried the solution but the issue still exists. 

 

Ankita9_0-1666262310405.png

 

Arnaud Derancou
Kilo Guru

Your transform map is targeting cmdb_ci.

 

Do you map things into different classes or everything should go to cmdb_ci_db_mssql_database ?

if everything should go to cmdb_ci_db_mssql_database then you can change the target table of your transform map to this class instead of cmdb_ci. You can then use the standard field mapping.

 

Otherwise in your transform map, use Run script and put the code here, not in the field mapping. You'd have to enclose the 2 lines between a if so it will only apply to import record you want to map to "cmdb_ci_db_mssql_database". For testing purpose you can put the 2 lines without enclosing into the if statement.

 

 

 

Hi Arnaud,

 

Everything should go to 'cmdb_ci' and based on the child class passed in the Payload the validations should happen. As of now, I have enabled insert and update only for 'cmdb_ci_db_mssql_database' but in near future more classes will be added so the target table has been configured as cmdb_ci'.  

 

On the field mapping level, I had tried selecting 'cmdb_ci_db_mssql_database' as target table but it did not helped.

Also, as per your suggestion I tried executing the 2lines of code in the Run Script but no luck!!