Salesforce

How Do I Dynamically Set a Data Source Name? (Magic xpa 3.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Dynamically Set a Data Source Name? (Magic xpa 3.x)

Ordinarily, the Data source name is hard-coded in to the Data source name column in the Data repository. However, it can be overridden within your program, when the data source is declared, and in functions that access that data source. Further, you can set the name using logical names, so that the name can be set at runtime. These options are discussed in more detail below.

Overriding the Data source name in a declaration

When you declare a data source, either as a Main Source or as a Linked Source, you have the option of overriding the Data source name. To do this, you just set an expression in the Properties->Data source name -> expression column. Here, we have a copy of our “Customers” database called “CustomersAsia”.

Overriding the Data source name in a function

Now, if we wanted to find the number of records in our “CustomersAsia” table, we also need to specify that this is a different table. So instead of using

DBRecs('4'DSOURCE', ' ')

we would enter

DbRecs('4'DSOURCE,'CustomersAsia')

Here we are using the second parameter of the DbRecs function to override the Data source name at runtime. Several of the Db functions use a second parameter for this.

Using Logical Names for Data sources

However, it is not optimal to have these overrides hard-coded. A better idea is to use Logical Names so that the Data source name can be set at runtime. This is not only easier to maintain, but it gives us flexibility in other ways. For instance, instead of having just “CustomersAsia”, we could have “CustomersEurope” and “CustomersAustralia”. Or, we could have different named tables for different sets of archives.

Suppose we define a logical name %CustDB% for our Customers database. Then, our data source name would be %CustDB%, and our DbRecs function would read:

DbRecs('4'DSOURCE,%CustDB%)

You can also use logical names in the Data repository, allowing one table definition to be used for multiple actual tables at runtime.

Reference
Attachment 
Attachment