how to make string default value null in hyperledger composer model file - hyperledger-fabric

I want to make default value of a string parameter in a asset as null
for example
o String param
i should give default value of param as null.
Can anyone help with this?

You can't set a default value of null in the model file, and if you try and set it to null in a Transaction Function it will not be set and will be undefined.
If you create it as an Optional field and do not set a value it will still be undefined.
You can set a default of "" - an empty string. Which will return a typeof String rather than undefined.
You don't specify why you want null, but with both the empty string or the undefined value they should both return false to the test !(param)

Put default value like this
o String param default=""

Related

What is the equivalent of "" for booleans in terraform?

I have a module that controls a handful of similar resources, and many of the settings in those resources are the same; so I've created global defaults that all of the resources in my module can refer to.
I want to have a set of default variables in my module and a set of variables that can override the default if the caller of my module decides to pass those in. What I've been using for strings is below (these are all in the same variables.tf file in my module).
My defaults:
variable "default_env" {default="test"}
My placeholder variables to allow calling resources to set them:
variable "x_env" {default=""}
variable "y_env" {default=""}
variable "z_env" {default=""}
And my attempt at guiding the user of the module towards which variables should be available for being overridden:
locals {
env = "${var.x_env != "" ? var.x_env : "${var.default_env}"}"
env = "${var.y_env != "" ? var.y_env : "${var.default_env}"}"
env = "${var.z_env != "" ? var.z_env : "${var.default_env}"}"
}
However, I can't figure out how to do this properly with booleans because I can't figure out how to create an empty boolean variable. My only option seems to be to also set a default value as part of my override variables:
variable "x_lock" {default=true}
Is there a way I can declare this in such a way that we don't have to maintain two sets of default values (1: variable "default_lock" {default=true}, 2: variable "x_lock" {default=true})?
I've tried doing:
variable "x_lock" {
type = bool
default = ""
}
But I obviously get an error that "" is not compatible with bool.
How else can I go about this?
The absence of a value is represented in Terraform by the keyword null, which is valid for any type.
Given that, in order to distinguish between true, false, and not set at all you can define a variable like this:
variable "x_lock" {
type = bool
default = null
}
Note that it's not really true to say that this is "the equivalent of an empty string for booleans". An empty string is not equal to null, and so if you want to explicitly represent the absence of a string it can often be best to use null for that too:
variable "x_env" {
type = string
default = null
}
...that way you can recognize an empty string as distinct from no string at all, similar to distinguishing false from no boolean at all.
null has a slightly different meaning in the context of a default than it does elsewhere. Setting default = null specifies that an input variable is optional without providing a default value for it. Or, if you like, saying that its default value is null.
An advantage of using null in this way is that you can pass that argument on as-is to any optional resource argument and it will be interpreted as if that argument were not set at all, rather than as if it were set to a default value.
There is also a further "special power" for null: if you use the splat operator [*] with a non-list value then it will return a single-element list for a non-null value and an empty list for a null value. This can be particularly useful if you are intending to use the "null-ness" of the value to decide whether or not to create a resource or a nested block:
variable "subscription_id" {
type = string
default = null
}
data "azurerm_subscription" "example" {
# Will be an empty set if `var.subscription_id` is null, or
# a single-item set if it is a non-null string.
for_each = toset(var.subscription_id[*])
subscription_id = each.key
}

How to check any response value matches its property value

I have a piece of code below that checks that every value of regionId (found under region.hotels.regionId) matches its property value regionid_request.
def response = messageExchange.response.responseContent
def json = new JsonSlurper().parseText(response)
def regionid_request = messageExchange.modelItem.testStep.testCase.testSuite.getPropertyValue("regionid") as Integer
region.hotels.each { hotel ->
assert hotel.regionId == regionid_request
}
I want the code above to perform slightly differently. Instead of saying each regionid needs to match its property value, I just want any of regionid to match its property value. In other words I want to ensure when I have my response, that at least one of the regionIds matches the property value.
What needs to be changed above to match this condition?
Thank you,
Just
assert region.hotels.regionId.contains(regionid_request)

How can i get value from geb content?

I have some geb content like this
buttonName(wait: true){$("a.btn_primary")}
I need get value from {} i.e. i need string $("a.btn_primary")
For example def value = "$("a.btn_primary")"
If your buttonName is correct, then try this:
def value = buttonName.text()
Cheers!
Try
def value = buttonName.value()
if .text() does not work.
From The Book of Geb,
"The value of input, select and textarea elements can be retrieved and set with the value method. Calling value() with no arguments will return the String value of the first element in the Navigator.
Calling value(value) will set the current value of all elements in the Navigator. The argument can be of any type and will be coerced to a String if necessary. The exceptions are that when setting a checkbox value the method expects a boolean (or, an existing checkbox value) and when setting a multiple select the method expects an array or Collection of values."
Hope it works out!

Checking for Null Values in CRM 2011 Custom Workflow Activity

I am trying to perform some logic in a CRM 2011 Custom Workflow Activity with some attributes from the calling entity. I am having an issue with determining whether a particular attribute is null or not. I have tried seemingly all combinations of GetAttributeValue and the Attributes collection, but it seems that I will always get either a Specified Cast is not Valid or Object Reference Not Set to an Instance of an Object error when there is a null value for an attribute I'm trying to access. Does anyone know the correct method for accessing an attribute that may be null? In this example, I am working with attributes of the Guid/Entity Reference type.
You can always check to see if the attributes collection contains the specific attribute that you're looking for, but you shouldn't even have to do that. All Non-nullable types (Guid, DateTime, etc) are stored as nullable types in the Attributes collection and that's probably your problem. Try something like this ( assuming late bound):
var isValid = entity.GetAttributeValue<bool?>("new_IsValid");
CRM never returns a non-nullable value. Even things that you think would be null (bool, DateTime, int, etc) are returned as their nullable equivalent. A non-nullable cast will still succeed if the value is not null, but if the value is null, it'll give you a null reference error;
object a = new bool?(true);
bool value = ((bool)a); // Works
object b = new bool?();
bool value = ((bool)b); // Null Ref Error
This syntax ended up working for me:
//if current outside counsel not null, grab GUID value
if (thisCase.lgl_outsidecounselid != null)
{
currentOCGUID = thisCase.lgl_outsidecounselid.Id;
}
//it's null, set Guid to Guid.empty
else
{
currentOCGUID = Guid.Empty;
}

(SPFieldLookupValue) splistitem of Lookup type throws Object reference not set to an instance of an object exception

I have a sharepoint list which has some Lookup fields. When I iterate through the items in code, I get the following error:
Object reference not set to an instance of an object.
This error appears only on lookup fields when they are not filled in with any value. I tried to use SPFieldLookupValue to check for null values, but I still get the error.
This is how I check for null values:
SPFieldLookupValue value = new SPFieldLookupValue(listItem[columnDisplayName].ToString());
if (value.LookupValue != null)
Any help guys?
The reason why you get this exception lies here: listItem[columnDisplayName].ToString() because listItem[columnDisplayName] have no value and returns null you trying to call ToString() on null object so it throws "Object reference not set to an instance of an object exception".
If you simply want to check if item field is not null then do like that:
if (listItem[columnDisplayName]!=null)
{
//here you can access listItem[columnDisplayName] safely
}

Resources