The CreatorCon Call for Content is officially open! Get started here.

How do I automatically run a transform when a new record gets entered into a table using a script?

123456789456123
Kilo Contributor

Once an item gets entered into the table, imp_sccm2012v2_software, how can I automatically run a transform on that data that was just entered so it can go to another table? So far I have a small script that works but only if you enter in the import set sys_id. I want this script to run a transform on every new data entry. Can this even be done? Below is my script.

current.update();

var mgr = new GlideRecord("sys_transform_map");

mgr.addQuery("source_table", "imp_sccm2012v2_software");

mgr.query();

if (mgr.next()) {

gs.setRedirect("run_import.do?sysparm_set=" + current.sys_id); //if I enter in a unique set sys_id here it works but only for that one item.

} else {

gs.addInfoMessage("Please create a transform map first");

gs.setRedirect("sys_transform_map.do?sys_id=-1&sysparm_query=source_table=" + "imp_sccm2012v2_software");

}

Thank you.

6 REPLIES 6

I gave the business rule a shot. My script is not doing what I want it to do. I want it to get the display name, the version and the date it was created and insert those values into another table as a new record. Would you mind taking a look at my script?



(function executeRule(current, previous /*null when async*/) {



var rec = new GlideRecord('imp_sccm2012v2_software');


rec.addQuery('created','today');


var created = rec.created;


var display_name = rec.display_name;


var version = rec.version;


rec.query();




var gr = new GlideRecord('cmdb_sam_sw_install');


gr.initialize();


gr.installed_on = created;


gr.display_name = display_name;


gr.version = version;


gr.insert();



})(current, previous);


randrews
Tera Guru

i am a little confused by how you are getting your data in.. the imp in the table name implies it is imported data.. how is it getting into the system.. via scheduled data import manual upload of a spreadsheet or how?