Pattern EVAL script not working as expected, please provide your valuable insights

Arun96
Tera Expert

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

Arun96_0-1748961117337.png

 

I'm using a 'Set Parameter Value' step to set the value for the field 'u_replicated_database'.

Arun96_0-1748969763126.png

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,

=============================

Arun96_1-1748969865171.png

 

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.

 

1 REPLY 1

Abbas_5
Tera Sage
Tera Sage

Hello @Arun96,

 

The provided data indicates that the MSSQL Pattern update is using a SQL command to determine values for the 'replicated database' table, specifically the 'database' and 'availability_group' variables. The 'database' variable has six values: ExUMDB,tempdb,master,model,SQL_IMDB,msdb, while the 'availability_group' variable has values AG -D-16P1120,NO,NO,NO,NO,NOThe 'replicated database' table appears to be used to track the availability group information for each database. 
Explanation:
  • 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. 
     
Key Points:
  • 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. 
     
In essence, the MSSQL Pattern update is automating the process of updating the 'replicated database' table based on the output of a SQL query, specifically focusing on identifying and tracking databases that are part of Availability Groups.
 
If this is helpful, please hit the thumbs up button and accept the correct solution by referring to this solution in future it will be helpful to them.
 
Thanks & Regards,
Abbas Shaik