Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Query regarding pattern

Khasim khan
Tera Contributor

What’s the exact answer for this?

IMG_3092.jpeg

1 ACCEPTED SOLUTION

SwarnadeepNandy
Mega Sage

Hello @Khasim khan,

 

The correct answer is D.

There is a tabular variable named ‘name_details’. This is because the value uses the syntax $name_details[1] to access the first row of the tabular variable. A scalar variable would not have brackets or an index. This value is not from a WMI query operation step, but from a pattern step. A WMI query operation step would use the syntax wmic <query> to execute a WMI query. This value can be used in a pattern step, as long as the variables are defined and valid. For more information on pattern steps, see Pattern Steps - ServiceNow Docs. For more information on WMI queries, see Querying WMI - Win32 apps | Microsoft Learn.

 
Kind Regards,
Swarnadeep Nandy

View solution in original post

7 REPLIES 7

SwarnadeepNandy
Mega Sage

Hello @Khasim khan,

 

The correct answer is D.

There is a tabular variable named ‘name_details’. This is because the value uses the syntax $name_details[1] to access the first row of the tabular variable. A scalar variable would not have brackets or an index. This value is not from a WMI query operation step, but from a pattern step. A WMI query operation step would use the syntax wmic <query> to execute a WMI query. This value can be used in a pattern step, as long as the variables are defined and valid. For more information on pattern steps, see Pattern Steps - ServiceNow Docs. For more information on WMI queries, see Querying WMI - Win32 apps | Microsoft Learn.

 
Kind Regards,
Swarnadeep Nandy

Hello @Khasim khan,
Please mark my answer correct if you feel it solved your issue. It will help other fellow community members.

 

Kind Regards,

Swarnadeep Nandy

@SwarnadeepNandy 

can you provide examples for scalar, tabular variables ?

 

Hello @Khasim khan,

Scalar and tabular variables are types of variables that can be used in ServiceNow patterns to store and manipulate data. Scalar variables are single-valued variables that can hold a string, a number, or a boolean value. Tabular variables are multi-valued variables that can hold a table of data, where each row is an array of values. Here are some examples of how to define and use scalar and tabular variables in ServiceNow patterns:

  • To define a scalar variable, you can use the syntax var <variable_name> = <value>;. For example, you can define a scalar variable named hostname and assign it the value "server1" as follows:

 

var hostname = "server1";​

 

  • To define a tabular variable, you can use the syntax var <variable_name> = []; and then use the push() method to add rows to the table. For example, you can define a tabular variable named name_details and add two rows of data as follows:

 

var name_details = [];
name_details.push(["John", "Smith", "Manager"]);
name_details.push(["Jane", "Doe", "Analyst"]);​

 

  • To access a scalar variable, you can use the syntax <variable_name>. For example, you can access the value of the scalar variable hostname as follows:

 

gs.info(hostname); // Prints "server1"​

 

  • To access a tabular variable, you can use the syntax <variable_name>[<row_index>][<column_index>]. For example, you can access the value of the second column of the first row of the tabular variable name_details as follows:

 

gs.info(name_details[0][1]); // Prints "Smith"​

 

For more information on how to work with scalar and tabular variables in ServiceNow patterns, you can refer to these resources:

 

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy