You are here: User Guide for PaperSave for Dynamics GP > Appendix > JavaScript Intellisense

JavaScript Intellisense

The main purpose to introduce this feature is to improve the end user experience in writing the script in script editor window. You will experience a more easy and convenient way of writing scripts in script editor window for various classes like Profile, Parameter, Globals etc. So this will ultimately reduce the human error caused during writing the scripts. Moreover, on hovering cursor over the functions/methods available in the list for the respective class, you will be able to view prompt help for the same.

 

Let us understand this with the help of below given example:

 

In the below given script, previously you had to write whole script manually with no list of functions/methods available for the respective class.

 

if (Parameter.Manager_Threshold == '15000')

{

 PaperSave.ShowMessage("Approve","PaperSave");

}

else

{

 PaperSave.ShowMessage("Reject",'PaperSave');        

}

 

But with JavaScript Intellisense feature (as shown below), now as you will write the class name followed by dot(.), related functions/methods available for the respective class will be listed. You can also view the prompt help in the tool tip on hovering the cursor over the respective functions/methods as displayed in below screen.

 

Moreover, you will experience an autocomplete of Single Quotes, Double Quotes and Curly Braces while you press the respective keys in the script editor.

 

javascript intellisense.zoom75
Click on image to magnify/shrink

 

Below are the examples for all the classes that support JavaScript Intellisense:

 

1. Profile.: Profile.{ProfileFieldName, ContextParamerters}

 

As you write Profile. in the editor window, all the available Profile Fields will be listed in the drop-down as displayed in below screen.

 

Note:

Please take a note that if the Workflow User Name exists in the format as Domain Name\User Name, then for PaperSave Web while using WF_user Paramter in the script, you will have to write Workflow User Name as "Domain Name\\User Name. Following is the example:

 

Profile.WF_user"Soldev\\Administrator";

 

javascript intellisense1.zoom75
Click on image to magnify/shrink

 

2. Parameter.: Parameter.{WorkflowParameter}

 

As you write Parameter. in the editor window, all the configured Workflow Parameters for the respective Workflow will be listed in the drop-down as displayed in below screen.

 

javascript intellisense2.zoom75
Click on image to magnify/shrink

 

3. Globals.:

 

As you write Globals. in the editor window, "Add" and "getVal" function will be listed in the drop-down as displayed in below screen.

 

javascript intellisense3.zoom75
Click on image to magnify/shrink

 

4. PaperSave.: PaperSave.{Methods}

 

As you write PaperSave. in the editor window, all the available Methods will be listed in the drop-down as displayed in below screen.

 

javascript intellisense4.zoom75
Click on image to magnify/shrink

 

ExecuteSQLServerQuery (Connection String, Command, ExecuteClientSide (optional), Data AccessServiceURL (Optional), UserName (Optional), Password (optional): There are six parameters of which Two are Required and other Four are Optional for this method as described below:

 

1. ConnectionString (Required): It is recommended to write the ConnectionString in below mentioned format only. Please take a note that while writing the Connection String, it is highly recommended to use Windows Authentication mode only and NOT SQL Server Authentation Mode due to security reasons.

 

Connection String Recommended Format:

 

1. Data Source={Server Name};Initial Catalog={DatabaseName};Integrated Security=True;MultipleActiveResultSets=True    

  OR

   Data Source={Server Name};Initial Catalog={DatabaseName};User ID={SQL User Name};Password={SQL Password};MultipleActiveResultSets=True

 

 

2. Driver={SQL Server};Server=ServerName;Database=DatabaseName;Trusted_Connection=yes

  OR

   Driver={SQL Server};Server=ServerName;Database=DatabaseName; User Id=myUsername;Password=myPassword;

 

  OR

 

    Provider=SQLOLEDB;Server=ServerName;Database=DatabaseName;Trusted_Connection=yes

    OR

    Provider=SQLOLEDB;Server=ServerName;Database=DatabaseName; User Id=myUsername;Password=myPassword;

 

2. Command (Required): This parameter allows you to write the query that has to be executed against the database of the given Connection String.

 

Possible Customizations:

We don’t support direct calling a stored procedure because a Stored Procedure can return multiple result sets and we do not have support for statements that return multiple result sets. If you desire this to be done, then you need to use the following strategy in the script you are using from within our javascript:

 

Declare @tablevar table(col1,..)

insert into @tablevar(col1,..) exec MyStoredProc 'param1', 'param2'

SELECT col1, col2 FROM @tablevar

 

Following example explains this more clearly:

 

For Example: Below is a sample Stored Procedure that returns the columns based on the parameter passed while executing stored procedures from java script.

 

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

 

ALTER PROCEDURE testps

(@Id bigint)

 

AS

BEGIN

 

 SET NOCOUNT ON;

  select ID,ConfigName,ConfigValue from Config where ID = @Id;

 

RETURN

end

 

If you want to retrieve above three columns then you have to prepare query as below:

 

var con = "Driver=SQL Server;Server=hvtest3;Database=PaperSave;Uid=sa;Pwd=abc123$$$";

 

var query = "DECLARE @users1 TABLE (CID int,Cname varchar(500),CValue varchar(4000)) INSERT into @users1(CID,Cname,CValue) exec testps @Id='2' SELECT CID,Cname,CValue from @users1";

 

var result=PaperSave.ExecuteSQLServerQuery(con,query);

 

PaperSave.ShowMessage("ConfigName :- " + result[0].Cname);

 

 

3. ExecuteClientSide (Optional): This parameter accepts only Boolean value like True or False and it is relevant only in the case of Windows. By default the value for this parameter will be False and the script will be executed on Server side. For PaperSave Windows based applications, if the value is set to "True" then the script will be executed at Client side for client side events like Pre-script, Post-script, On-Exit etc. However, for PaperSave Web based applications, the script will be executed always on server side.

 

Note:

Please take a note that on Server side the query will be executed under the context of PaperSave Service Account User and not the local user account.

 

4. DataAccessServiceURL (Optional): This parameter can be used when PaperSave is hosted on Cloud and Host Application's Database is NOT directly accessible and also in a case when you want to access another remote database provided that user has installed Data Access Service in that environment. For this parameter, you will have to provide the Data Access Web Service URL.

 

5. UserName (Optional): Enter the User Name who has the necessary rights to execute the given query on Host or Non Host Application's Database. Please make sure that you enter the User Name in the format as DomainName\\UserName.

 

6. Password (Optional): Enter the respective Password of the User.

 

sql query.zoom75
Click on image to magnify/shrink

 

GetListofUsersInAGroup: This function allows you to get the list of users in a group from the PaperSave Application Server's domain (On-Premise) or in a group of users setup within PaperSaveCloud. The resultset of users is returned as a JavaScript array. Here, you need to pass the GroupName as string within double quotes ("").

 

javascript intellisense5.zoom75
Click on image to magnify/shrink

 

5. ScriptResult:

 

As you will write ScriptResult. in the editor window, all the available Functions will be listed in the drop-down as displayed in below screen.

 

ScriptResult.CancelScript: This function can be used in a Script to prohibit the Event from getting executed if it does match some condition. You need to pass the value for this function as either "True" or "False". If the value for this function is "True" then in that case it will cancel the script from being executed. And if the value for this function is "False", then no action will be performed.
ScriptResult.ShowCancelMessage: This function can be used to display a message box from the JavaScript execution. When the value of the ScriptResult.CancelScript is set to "True" in that case it will display a message box when cancelling the script, in case where the value of the ScriptResult.CancelScript is set to "False" then it will not display the said message box.

 

Note:

Instead of using above two functions for executing Cancel Script, you have an ability to use a single method named 'PaperSave.CancelScript'. Click here to know more.

 

scriptresult-1.zoom85
Click on image to magnify/shrink

 

Back to Script Activity (Workflow 1.0)

Back to Script Activity (Workflow 2.0)

Back to Pre-Script & Post-Script Workflow 1.0

Back to Pre-Script & Post-Script Workflow 2.0