Document ID transform Map

free
Kilo Contributor

Hi,

How can i map any value to document Id type field in transform Map?

1 ACCEPTED SOLUTION

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

I'm not certain why we are calling the script include and querying the dictionary at all as we already know the tables because they are being used to generate the query.   If the intent is that I don't know what table my id is for so I want it to try multiple tables then you can do something like the following untested script:



var tables = ['kb_category','kb_knowledge_base'];


var id = "25cd15c3ac6c728056e1781325626541";



for (var i = 0; i < tables.length; i++) {


        var gr = new GlideRecord(tables[i]);


        if (gr.get(id)) {


                  target.parent_table = tables[i];


                  target.parent_id = id;


                  break;


        }


                 


}



But if you know the table, it should be as simple as:



target.parent_table = "kb_knowledge_base";


target.parent_id = "25cd15c3ac6c728056e1781325626541";


In either case, I would remove the field mapping entries in favor of the on before script to guarantee ordering.


View solution in original post

18 REPLIES 18

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

So your script include returns an array?   Do you reduce it down to 1 string representing a table name somewhere?



You cannot set the parent_table field to multiple values as the sys_id can only exist in 1 table, so without some more to get it down to 1 value it will fail.



Also, the intent of the previous post was to get you to try the following to ensure the ordering.   This assumes that the sys_id represents a record in that table.   If it's a category, it will not work.



target.parent_table = "kb_knowledge_base";


target.parent_id = "25cd15c3ac6c728056e1781325626541";


so what should I do now? should I call script include in to my field mapping script and access its index?


Joe McCarty1
ServiceNow Employee
ServiceNow Employee

I'm not certain why we are calling the script include and querying the dictionary at all as we already know the tables because they are being used to generate the query.   If the intent is that I don't know what table my id is for so I want it to try multiple tables then you can do something like the following untested script:



var tables = ['kb_category','kb_knowledge_base'];


var id = "25cd15c3ac6c728056e1781325626541";



for (var i = 0; i < tables.length; i++) {


        var gr = new GlideRecord(tables[i]);


        if (gr.get(id)) {


                  target.parent_table = tables[i];


                  target.parent_id = id;


                  break;


        }


                 


}



But if you know the table, it should be as simple as:



target.parent_table = "kb_knowledge_base";


target.parent_id = "25cd15c3ac6c728056e1781325626541";


In either case, I would remove the field mapping entries in favor of the on before script to guarantee ordering.


its working now. thanks