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

My guess is the issue is in the script include or the sys_id doesn't belong to that table..   Verify that the parent_table field is actually being set to the table you expect and that the sys_id you are using is in that table.



Here is my test that worked as expected:



Screen Shot 2017-02-16 at 8.42.58 AM.png



Screen Shot 2017-02-16 at 8.45.08 AM.png



Screen Shot 2017-02-16 at 8.45.32 AM.png


but when I only map to parent table. still it is not showing any data.


Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Parent table is a field in it's own right that can be added to the form (see below).   Parent Id will not render correctly unless both fields are set correctly but you can add parent table to the form or list to verify just that piece of it.   If parent table is set correctly, then your issue will be the sys_id:



Screen Shot 2017-02-16 at 8.56.32 AM.png


Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Just had someone make another suggestion based on an experience they've had in the past with validation that table is set before the id.   Can you try moving both mappings into an onBefore script making sure that the table field is assigned before the id field?   There is no one of ensuring order with the field mappings.   Let me know if that helps.   I've never personally run into it.


i have tried this in transform script on before,



target.parent_table = "kb_knowledge_base";



but it's not working.


in my parent_table field value comes from script include, which is following,



var KBCatTables = Class.create();


KBCatTables.prototype = {


      initialize: function() {


      },


     


      process: function() {


              var result = [];


              var dict = new GlideRecord("sys_dictionary");


              dict.addNullQuery("element");


              var gc = dict.addQuery("name", "kb_category");


              gc.addOrCondition("name", "kb_knowledge_base");


              dict.orderBy("name");


              dict.query();


             


              while (dict.next()) {


              result.push("" + dict.name);


              }


           


              return result;


      }


}