cancel
Showing results for 
Search instead for 
Did you mean: 

Expression File Functions and Read Expression

amit_saroha
New Contributor III

Hi,

Below is a sample expression file is shown in another thread and I want to understand what exactly the functions are doing and their purpose. I also want to understand how the expression works to read the file values.

File contents -

“Accounts”: {
“projectSpace”: {
“projectName”: {
“Salesforce”: {
“Dev”: {
“account_name”: “Salesforce CIDEV”
},
“PRD”: {
“account_name”: “Salesforce CIDPRD”
}
}
}
}
}

"getOrgName": pipe.plexPath.split("/")[1],
"getProjectSpace": x => x.split('/')[2],
"getProject": x => x.split("/")[3],
"whereAmI": this.getOrgName.toLowerCase().contains("prod") ? "Prod" : (this.getOrgName.toLowerCase().contains("test") ? "Test" : "Dev"),
"getAccount": (path,type) => this.Accounts[this.getProjectSpace(path)][this.getProject(path)][type][this.whereAmI]

Expression - (How it works)

lib.expr_lib.getAccount(pipe.projectPath,“Salesforce”)

6 REPLIES 6

viktor_n
Contributor II

Hi @amit.saroha,

Functions in this particular expressions file all together are used to map to particular “account_name” depending in which projectSpace, project and environment you are.

SnapLogic functions:

  • pipe.plexPath - Returns path of the snaplex which is executing the process.
  • pipe.projectPath - Returns path of the project that is executing at the time.

Expressions file functions:

  1. getOrgName - Returns the name of the organization. It is splitting the path from plexPath by “/” and selects the second element(index of 1). This also can be get from pipe.projectPath function.

  2. getProjectSpace - Returns the name of the projectSpace. Selects the projectSpace on the same way as the organization is selected. Difference is that the pipe.projectPath is not hardcoded in the expressions file as the pipe.plexPath is, but is passed as parameter.

  3. getProject - Returns the project name. Works exactly the same as for the projectSpace but is selected different element.

  4. whereAmI - This returns the environment.

  • this keyword is used when you referring to some element that is on the same scope, as the function that you use, and you need to access. As it is in the expression file, from whereAmI is called getOrgName function.

  • getOrgName will return the organization name and it will check if the organization have “prod” then will return “Prod”, otherwise will check for ‘test’ and at the end if there is not prod and test inside organization will return ‘Dev’.

  • Keep in mind that returned value from this function needs to be the same as the environment element inside Accounts object.

5.getAccount - This function maps through the Accounts object with help from the functions above.
Accepts two parameters:
First one is the projectPath that getProjectSpace and getProject are using.
Second is string that will be used for the mapping to the correct object beside the values from the functions.

this.Accounts[this.getProjectSpace(path)][this.getProject(path)][type][this.whereAmI]
So, this is what will look like after the above functions are called:
this.Accounts['projectSpace']['projectName']['Salesforce']['PRD']
And will return that what will find on that location, if finds anything. If we get Accounts from the sample above will return this account number.

{
 "account_name": "Salesforce CIDPRD"
}

Regards,
Viktor

koryknick
Employee
Employee

@amit.saroha - I created a starter pack for expression libraries which might help you understand how they work.