Notifications

60 views

Description

Symptoms


When we are using the temporary/target tables' reference field value as conditional operator then it may fail.

Sample:

  • Let's assume we have a pattern on cmdb_ci_linux_server table and the data is populated on this table with a reference field as support_group (which is a reference type field).
  • Now, we wanted to add a new step at the end to check if one of the reference field value is empty or not and if its empty then you wanted to populate with some hardcoded value.
  • For we need to add a condition if the cmdb_ci_linux_server.server is empty or not. And if its empty you will pass some hardcoded value to it.

Sample Pattern looks as below:

  • The issue here is, even though the support_group is empty it may fail the condition. 

Release


Jakarta or later

Environment


All

Cause


Here, since we are checking the reference field type it is returning the data as an object. Since it is an object with empty values in it is not equals to undefined/null/"". And so the system/script thinks that there is some value and the condition always fails.

Resolution


  • Convert the reference field value to a string using the method toString().
  • Within the condition, replace the code "$cmdb_ci_linux_server[*].support_group" with "$cmdb_ci_linux_server[*].support_group.toString()".
  • The best way is to declare a temporary variable (assume tempGroup) and pass the value of "$cmdb_ci_linux_server[*].support_group" and then stringify the variable tempGroup like $tempGroup.toString().

The final pattern may look as follows:

Additional Information


Article Information

Last Updated:2019-08-02 20:53:29
Published:2019-02-04
Pasted image.pngPasted image.png