Dynamic Expressions (New)

Updated 2 weeks ago by Copado Solutions

Some of the expressions included in this article require the latest version of Copado (v18.23.1). If you are using a previous version, please refer to the Dynamic Expressions article.

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

Dynamic expressions run on different contexts and require different context Ids depending on the job the function is executing. For example, the expression {Context.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 User record Id of the logged-in user.

Copado has six types of dynamic expressions:

  • 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:

System Property Expression

Use

{$User.Property.LogLevel}

Use this expression to look 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}

Use this expression to look for the value of the System Property record related to the Pipeline record linked to the promotion.

{$Source.Property.DBName}

Use this expression to look for the value of the System Property record linked to the Environment record which is the source environment of the deployment.

{$Destination.Property.DBName}

Use this expression to look for the value of the System Property record linked to the Environment record which is the destination environment of the job step.

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

User Expressions 

User Expression

Use

{$User.FieldName}

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

Repository Expressions

Repository Expression

Use

{Context.Repository.Credential}

Use 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 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
If you are building an expression for Git credentials, the name of the expression or parameter must be git_json.

SObject Expression

There are two different sObject expressions:

SObject Expression

Use

{Context.FieldName}

Use this expression to look for a particular field in a given object record.

{Context.FieldName__r.ParentField__c}

Use this expression to search for a field in a related parent record.

The context Id you need to provide in these cases is the Id of the record from which you want to get the value.

Job Expressions

There are six types of job expressions:

Job Expression

Use

Example

{$Job.Step}

Use this expression to reference a value from the current step in a job template.

{$Job.Step.Name}

{$Job.FirstStep}

Use this expression to reference a value from the first step in a job template.

{$Job.FirstStep.Name}

{$Job.FirstStep.DataJson.key1}

{$Job.PrevStep}

Use this expression to reference a value from the previous step in a job template.

{$Job.PrevStep.Name}

{$Job.PrevStep.DataJson.key1}

{$Job.NextStep}

Use this expression to reference a value from the next step in a job template.

{$Job.NextStep.Name}

{$Job.LastStep}

Use this expression to reference a value from the last step in a job template.

{$Job.LastStep.Name}

{$Job.ExecutionParent}

Use this expression to access a field value of the Job Execution parent record.

{$Job.ExecutionParent.Name}

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:

Credential Expression

Use

{$Source.Credential.SessionId}

Use this expression to get the logged-in user credential or default credential for the source environment, querying the sessionId.

{$Destination.Credential.SessionId}

Use this expression to get the logged-in user credential or default credential for the destination environment, querying the sessionId.

{$Source.Credential.Endpoint}

Use this expression to get the logged-in user credential or default credential for the source environment, querying the endpoint.

{$Destination.Credential.Endpoint}

Use this expression to get the logged-in user credential or default credential for the destination environment, querying the endpoint.

{Context.Credential.Endpoint}

Use this expression to get the logged-in user credential or default credential for the Environment record specified as context, querying the endpoint.

{Context.Credential.SessionId}

Use this expression to get the logged-in user credential or default credential for the Environment record specified as context, querying the sessionId.

The context Id you need to provide when using source and destination expressions is the Job Step record Id. For context 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:

Dynamic Parameter

Use

{$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 destination environment of the deployment.

{$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 Job Step record.


How did we do?