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

dwada1
Kilo Expert

Hi Ben,



It looks like what you have there is correct, though to be sure I'd need to see your whole setup. I'm guessing your script creates a new import set for every item, so if you're looking to run all items in a single import set, you'd have to modify your other script to do so.



I'm wondering what the business case is here though? Have you considered instead using REST?


Derek,


I haven't considered using REST is there a link you can provide that shows me how to use REST from within a script?


shilpiharitwal
Mega Expert

Helo Ben G,



Why won't you try to go with Business Rule.



You can set a after (insert) business rule on current table and insert data to required data.



Regards,


Shilpi Sharma


Shilpi,



You're right. I am going to try to do this instead. I am not sure I know how to script this but I will give it a shot.