Below is an example demonstrating how you can use a script to respond to an element that had a DzSimpleElementScriptData added to it being loaded, and how to access additional information stored in the data item's settings to control how the script executes.
See Also: Post-Load Script Data Item Add
// Define an anonymous function; // serves as our main loop, // limits the scope of variables (function(){ /*********************************************************************/ // String : A function for retrieving a translation if one exists function text( sText ) { // If the version of the application supports qsTr() if( typeof( qsTr ) != "undefined" ){ // Return the translated (if any) text return qsTr( sText ); } // Return the original text return sText; }; /*********************************************************************/ // Declare working variables var sMessage; // Define common strings var sButton = text( "&OK" ); var sTitle = text( "Data Item Info" ); // 'DataItem' is a global transient variable, available when // this script is executed as a 'post load data item' // If we didn't find the 'DataItem' global transient; // this script was executed outside the context of a 'post load data item' if( typeof( DataItem ) == "undefined" ){ // Construct the message sMessage = "Oops... 'DataItem' doesn't exist."; // If we have the 'DataItem' global transient } else { // Get the owner of the data item var oElement = DataItem.getOwner(); // Define the lines of the message var aMessage = [ "Element Class: " + oElement.className(), "Element Name: " + oElement.getName(), "Data Class: " + DataItem.className(), "Data Name: " + DataItem.name ]; // If the data item is of the type we expect if( DataItem.inherits("DzSimpleElementScriptData") ){ // Get some extra info aMessage.push( "Data Script: " + DataItem.getScriptFilePath() ); } // Get the settings for the data item var oSettings = DataItem.getSettings(); // Get the value for the message key; default to something we know it won't be aMessage.push( "Data Settings: " + oSettings.toJsonString() ); // Convert the lines into a string sMessage = aMessage.join( "\n" ); } // Display the message MessageBox.information( sMessage, sTitle, sButton ); // Finalize the function and invoke })();