User Tools

Site Tools


syntax_editor_macros

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
syntax_editor_macros [01/07/2025 13:13] johnsonjohnsyntax_editor_macros [01/07/2025 13:16] (current) johnsonjohn
Line 37: Line 37:
 ====c_GeneratingMessages==== ====c_GeneratingMessages====
 <code> <code>
 +//text 
 +//alert(), addInfoMessage(), showFieldMsg(), jslog(), addDecoration() 
 +  
 +//Context: Most client side code. 
 +  
 +//Ways to generate messages from client side code: 
 +//Use the alert() function to show a prominent and blocking modal dialog which must be explicitly dismissed for execution to continue. 
 +//Display a message to the user from Client code using g_form.addInfoMessage() or g_form.addErrorMessage() 
 +//Use g_form.addDecoration() to show a small graphic symbol by a form field label.  A mouse-over popup hint may be included, and a color may be specified. 
 +//Use g_form.flash() to display a flashing colored background box behind a form field label. 
 +//Use the confirm() function to display a modal popup dialog to get a response (OK or Cancel) from the user before continuing execution. 
 +//Use the jslog() function to write a message to the web browser console. 
 +function onLoad() { 
 +                alert("My Alert Message"); //Modal dialog with OK button.  
 +                 
 +                g_form.addErrorMessage("My Error Message"); //Wide message at top of form in Red. 
 +                g_form.addInfoMessage("My Info Message"); //Wide message at top of form in Blue. 
 +                 
 +                g_form.showFieldMsg("name", "My Field Message"); //Message UNDERNEATH field.  Same width as field.  Displayed in blue. 
 +                g_form.showFieldMsg("name", "My Field Message - info", "info"); //Again, message UNDERNEATH field.  Same width as field.  Displayed in blue. 
 +                g_form.showFieldMsg("name", "My Field Message - error", "error"); //Message UNDERNEATH field.  Same width as field.  Displayed in red. 
 +                g_form.showFieldMsg("name", "My Field Message - warning", "warning"); //Message UNDERNEATH field.  Same width as field.  Displayed in orange. 
 +                 
 +                jslog("My jslog Log"); //Sends a message to the web browser console log seen using F12. 
 +  
 +                g_form.addDecoration("name", "icon-user", "This icon is called icon-user"); //Icon to the left of field. 
 +                g_form.addDecoration("name", "icon-tree", "This icon is called icon-tree", "color-green"); 
 +                g_form.addDecoration("name", "icon-lightbulb", "This icon is called  icon-lightbulb", "color-red"); 
 +                 
 +                g_form.flash("name", "#AAFACD", -4); //Yellow highlight bar over field for 4 seconds. 
 +  
 +                var vResult = confirm("My Confirmation Message") ? "User clicked OK" : "User clicked Cancel"; //Modal dialog with 2 buttons. 
 +                g_form.addInfoMessage(vResult); //Wide message at top of form in Blue. 
 +}
 </code> </code>
 ---- ----
Line 43: Line 76:
 ====c_GlideAjaxMethod==== ====c_GlideAjaxMethod====
 <code> <code>
 +//text 
 +//GlideAjax, addParam(), getXMLAnswer 
 +  
 +//From client side code, to invoke server side code asynchronously, instantiate a custom GlideAjax object. 
 +//Use the addParam() function, and by convention, the parameter named "sysparm_name" to specify which server side function to invoke. 
 +//Additional arbitrary parameters may also be specified with addParam(); In this example "sysparm_Prefix"
 +//Use getXMLAnswer() to invoke the server-side function and specify a callback function; in this example "finishClientSideWorkONE"
 +//Use a direct parameter in your callback function to make use of data returned by the server; in this case the parameter is named "answerFromServer"
 +function onLoad() { 
 +                g_form.addInfoMessage("BEGIN Client Script"); 
 +  
 +                var ga = new GlideAjax('zJWJ_AjaxFunctions'); //phoenixAjaxUtils is the name of a Server Side Script Include CLASS. 
 +                ga.addParam("sysparm_name", "getMyTitle"); //One parameter must be named sysparm_name.  It tells which function to invoke on the server. 
 +                ga.getXMLAnswer(finishClientSideWork); //Call server function.  When it's complete, then invoke "finishClientSideWork" back here on the client. 
 +  
 +                g_form.addInfoMessage("Additional Code on Client Side 1"); 
 +  
 +                var ga2 = new GlideAjax('zJWJ_AjaxFunctions'); //phoenixAjaxUtils is the name of a Server Side Script Include CLASS. 
 +                ga2.addParam("sysparm_name", "getMyTitleWithPrefix"); //Tells which function to invoke on the server. 
 +                ga2.addParam("sysparm_Prefix", "Sir "); //Additional custom parameter. 
 +                ga2.getXMLAnswer(finishClientSideWorkTWO); //Call server function.  When complete, then invoke "finishClientSideWorkTWO" back here on the client. 
 +  
 +                g_form.addInfoMessage("Additional Code on Client Side 2"); 
 +
 +  
 +function finishClientSideWork(answerFomServer) 
 +
 +                g_form.addInfoMessage("BEGIN finishClientSideWorkONE"); 
 +                g_form.addInfoMessage("Title from Server: " + answerFomServer); 
 +                g_form.addInfoMessage("END finishClientSideWorkONE"); 
 +
 +  
 +function finishClientSideWorkTWO(answerFomServerTWO) 
 +
 +                g_form.addInfoMessage("BEGIN finishClientSideWorkTWO"); 
 +                g_form.addInfoMessage("Title from Server w Prefix: " + answerFomServerTWO); 
 +                g_form.addInfoMessage("END finishClientSideWorkTWO"); 
 +}
 </code> </code>
 ---- ----
syntax_editor_macros.1736284394.txt.gz · Last modified: 01/07/2025 13:13 by johnsonjohn

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki