How do I automatically run a transform when a new record gets entered into a table using a script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 11:36 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 04:49 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 03:14 PM
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?