Changing Transform map action at run time

Pradnya6
Giga Contributor

I am trying to implement a transform map on "cmdb_ci_server" table (target table is "cmdb_ci_server"). I have some entries created in "cmdb_ci" table.
While running transform map on "cmdb_ci_server" table on Transform map script I am checking if the record with same name exist in the "cmdb_ci" if exist I want to change the action of the transform map. I am trying to achieve it with below line of code in transform map "Run Script".
action = 'update';
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('name', 'testServer.001');
gr.query();
if (gr.next())
{
target.sys_id = gr.sys_id;
}
so that even though the previous action was insert Record will update the existing record from cmdb_ci table.
Some how even after setting these values, I can see 2 entries created in the data base.

Or is there anyway, I can update the class of the record before transform map 'action' is decided ?

3 REPLIES 3

Ivan Martez
ServiceNow Employee
ServiceNow Employee

I believe you can do this with an onBefore transform map script. Check out the transform events here:
http://wiki.service-now.com/index.php?title=Transform_Map_Scripts#Transformation_Events


Pradnya6
Giga Contributor

Thanks Ivan, but that doesn't work.
If the 'action' of transform map is 'insert' it doesn't change the behavior of it. The transform map inserts new entry in cmdb_ci table. Is there any other way I can change the action on the fly?


Ivan Martez
ServiceNow Employee
ServiceNow Employee

You would most likely need to ignore the insert operation. You could do something like this



if (action == 'insert') { ignore = true; }

if (action == 'update') {
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('name', 'testServer.001');
gr.query();
if (gr.next())
{
target.sys_id = gr.sys_id;
}
}