Pattern EVAL script not working as expected, please provide your valuable insights
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2025 10:02 AM
Hi All,
I'm working on a MSSQL Pattern update, we have an existing extension to the main pattern.
New steps were introduced to set a field value based on the output we get after executing a SQL command.
Below is the output I'm getting after executing the SQL command.
In the pattern step 'replicated_database' is the table name and 'database' and 'availability_group' are the variables.
'database' variable hold the values - ExUMDB,tempdb,master,model,SQL_IMDB,msdb
'availability_group' hold the values -AG -D-16P1120,NO,NO,NO,NO,NO
I'm using a 'Set Parameter Value' step to set the value for the field 'u_replicated_database'.
Using an EVAL script in this, below is the script,
====================================
var availability_group = CTX.getAttribute("replicated_database[*].availability_group").toArray();
var replicated;
for (var i =0; i<availability_group.length; i++) {
replicated = "True";
if(availability_group[i] == "NO")
{
replicated = "False";
}
}
Below is the output of the EVAL script,
=============================
For the first database I was expecting the value 'True' , because the availability_group's first value is 'AG -D-16P1120'.
Please help me to get the correct values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 08:56 PM
Hello @Arun96,
ExUMDB,tempdb,master,model,SQL_IMDB,msdb
, while the 'availability_group' variable has values AG -D-16P1120,NO,NO,NO,NO,NO
. The 'replicated database' table appears to be used to track the availability group information for each database. -
SQL Command:The user is executing a SQL command within the MSSQL Pattern update to retrieve information about replicated databases.
-
replicated database
Table:This table likely stores data about databases that are part of an Availability Group. -
database
Variable:This variable likely holds the names of the databases, as seen in the output. -
availability_group
Variable:This variable likely holds the Availability Group name or status for each database. The "AG -D-16P1120" indicates that at least one database (ExUMDB) belongs to the specified Availability Group. -
Pattern Steps:The new pattern steps are designed to use the output of this SQL command to update the 'replicated database' table.
-
Availability Groups:The presence of "AG -D-16P1120" suggests that the databases are part of an SQL Server Availability Group, which enables high availability and disaster recovery.
-
Replication:The term "replicated database" implies that the data is being mirrored or synchronized across multiple instances, enabling high availability and redundancy.
-
MSSQL Pattern:The MSSQL Pattern likely involves automating tasks related to database replication and availability groups.