You are here: User Guide for PaperSave for Dynamics GP > PaperSave Configuration > PaperSave Settings > PaperSave JavaScript library functions
PaperSave JavaScript library functions

1. PaperSave.IsWindows()


This function can be used to identify whether the script being executed is from Windows or any Web application so as to determine if anything in the script depends upon Windows or Web.


2. PaperSave.ShowMessage(Message, Title)


This function can be used to display a message box from the JavaScript execution. Before you had to write several statements in script and show a message using the Popup(...) function, but now you can use PaperSave.ShowMessage so that the desired message text and title (title will be displayed from Windows script only) is automatically displayed.


3. PaperSave.ExecuteSQLServerQuery(ConnectionString, CommandText)


This function can be used to execute SQL query on a specified server depending upon the Connection String supplied. An SQL query can be any valid SQL statements with SELECT, INSERT, UPDATE or DELETE. For SELECT statements it will return an Array which can be used on the caller script. To know more about PaperSave.ExecuteSQLServerQuery, click here and refer the respective section.


4. PaperSave.CancelScript(ShowCancelMessage)


This function can be used in a PreScript to prohibit the Event from getting executed if it does match some condition. One need to pass the value for "ShowCancelMessage" parameter while using this function, the value can either be set to "True" or "False". When the value of the Parameter is set to "True" in that case it will display a message box as shown below, in case where the value of the parameter is set to "False" then it will not display the said message box.




Example: The example below shows the usage of the PaperSave JavaScript library. It decides whether the script is being executed from Windows (or web) and passes required parameters for the Connection String and SQL query by returning the result set. The code below highlighted in Green color shows an example of PaperSave.CancelScript(ShowCancelMessage) function.


var xVendorRows = [];

  xVendorRows = PaperSave.ExecuteSQLServerQuery("Provider=SQLOLEDB;Data Source=.\\development;Initial Catalog=TWO;Trusted_Connection=Yes;","Select VENDNAME, ZIPCODE from PM00200 where VENDORID like 'ACETRAV%'");
  xVendorRows = PaperSave.ExecuteSQLServerQuery("Data Source=.\\development;Initial Catalog=TWO;Integrated Security=True;MultipleActiveResultSets=True","Select VENDNAME from PM00200 where VENDORID like 'ACETRAV%'");

var vendorName="";

if(xVendorRows !=null)
  for(var i=0;i< xVendorRows.length;i++)
  vendorName = xVendorRows[i].VENDNAME;

if(profile.Amount == null || profile.Amount <= 0)
  PaperSave.ShowMessage("Please enter a value for Amount profile field.","PaperSave");


There are also some names for selected objects and functions to avoid casing related issues from user perspective while scripting for any PaperSave JavaScript library functions:

· You can use Globals or globals or GLOBALS for Global variables. Also you can use different cases for add (Add or ADD or add), exists (Exists or EXISTS) and getVal (GETVAL or getval or Getval or GetVal) functions.
· You can use Profile or PROFILE or profile for using profile fields.
· For ScriptResult (i.e. statements like ScriptResult, CancelScript etc. in PreScript) you can use Scriptresult or SCRIPTRESULT or scriptresult or scriptResult.
· Also you can use different functions with different casing as mentioned above.