Dynamic Expressions

Updated 1 week ago by Copado Solutions

Introduction

A dynamic expression is a container that stores values that can be referenced in a function.

Dynamic expressions run on different contexts and require different context Ids depending on the job the function is executing. For example, the expression {$RecordId.Repository.Credential} searches for credentials in a Copado Git Repository record. Therefore, the context Id for this expression is the Id of the Git Repository record. Similarly, if you want to get the value of a field in the User record, the context Id would be the logged-in user’s User record Id.

  • System property expressions 
  • User expressions
  • Repository expressions
  • SObject expressions
  • Step expressions
  • Credential expressions

Let’s review each of them in more detail.

System Property Expressions

System properties let you save sensitive and non-sensitive values in Copado. You can also create system properties to store environment variable values like application names or worker sizes, for instance. To do this, you can use the System Properties object in Copado. See the article How to Create a System Property for more information about creating a system property.

Let’s take a look at the different system properties Copado has:

  • {$User.Property.LogLevel}

This expression looks for the value of the System Property record linked to the User record of the user executing the function. This expression doesn’t require a context Id because Copado already has the Id of the logged-in user. 

  • {$Pipeline.Property.DBName}

This expression looks for the value of the System Property record related to the Pipeline record linked to the promotion. 

  • {$Source.Property.DBName}

This expression looks for the value of the System Property record linked to the Environment record which is the source environment of the deployment.

  • {$Destination.Property.DBName}

This expression looks for the value of the System Property record linked to the Environment record which is the destination environment of the deployment job.

The context Id you need to provide for these three expressions {$Pipeline.Property.DBName}, {$Source.Property.DBName} and {$Destination.Property.DBName} is the Id of the Deployment Job record.

User Expressions 

{$User.FieldName}

Copado uses this expression to look for a particular field within the User record of the logged-in user and replaces the expression with the value of that specific field.

Repository Expressions

{$RecordId.Repository.Credential}

Copado uses this expression to look for the credentials of the Git repository linked to the Git Repository record in Copado. The context Id you need to provide is the Id of the Copado Git Repository record. However, you can also use any object as the context Id for this expression as long as the object has the Git_Repository__c field with the Id of the repository.

Credentials are sent in JSON format and contain multiple values depending on the authentication type:

  • HTTPS
    • Username
    • Password
    • URL
    • Extra Headers
  • SSH
    • URL
    • SSH Key
    • Extra Headers
Whenever you are working with Git credentials, the name of the expression or parameter is always git_json.

SObject Expression

There are two different sObject expressions:

  • {$RecordId.FieldName} 
  • {$RecordId.FieldName__r.ParentField__c}

You can use these expressions to look for a particular field in a given object record or search for a field in a related parent record, respectively. In this case, the context Id you need to provide is the Id of the record from which you want to get the value.

Step Expressions

There are two types of step expressions:

  • {$RecordId.PrevStep.JSONResult}
  • {$RecordId.PrevStep.FieldName__c}

If you are working on a deployment process that contains various steps, you may want to store a value in one of the steps and then reference it in the following step. To do this, you can use a step expression.

Copado also uses step expressions in the function step that executes the promotion and the deployment in multi-cloud pipelines.

Credential Expressions

Credential expressions are used by a function to authenticate and connect to a Salesforce org in order to perform different automations in a source or a destination org.

There are six types of credential expressions:

  • {$Source.Credential.SessionId}
  • {$Destination.Credential.SessionId}
  • {$Source.Credential.Endpoint}
  • {$Destination.Credential.Endpoint}
  • {$RecordId.Credential.Endpoint}
  • {$RecordId.Credential.SessionId}

The context Id you need to provide when using source and destination expressions is the Deployment Job record Id. For recordId expressions, it is the Id of the Environment record linked to the credential.

Additional Dynamic Parameters

Apart from the main six types of expressions we have described above, Copado has also some dynamic parameters that you can reference in a function:

  • {$Pipeline.MyField__c}

This parameter looks for the value of a particular field in the Pipeline record linked to the promotion. 

  • {$Source.MyField__c}

This parameter looks for the value of a particular field in the Environment record which is the deployment’s source environment.

  • {$Source.MyLookup__r.MyOtherField__c}

This parameter looks for the value of a particular field in a related parent record in the Environment record which is the deployment’s source environment.

  • {$Destination.MyField__c}

This parameter looks for the value of a particular field in the Environment record which is the deployment’s destination environment.

  • {$Destination.MyLookup__r.MyOtherField__c}

This parameter looks for the value of a particular field in a related parent record in the Environment record which is the deployment’s destination environment.

The context Id you need to provide for all these parameters is the Id of the Deployment Job record.


How did we do?