Response object values not being set. Object Reference error

Response object values not being set. Object Reference error

  

I am trying to create an extension and use in my code.


My extension is having one input parameter and returning three attributes.


Below are the attributes of my Response object



Always when i am trying to set values of attributes, i am having object null reference error.


I checked the implemented classes and found out below objects being used. If i remove them and test by sample web application, it works fine. But if i remove them and publish, it comes back again from the Integration studio i believe.


I don't know the purpose or why they are being checked before setting values


public ENBenDetEntityRecord(params string[] dummy) {
ChangedAttributes = new BitArray(3, true);
OptimizedAttributes = new BitArray(3, true);
_ssName = "";
_ssAmount = "";
_ssStatus = "";
}


public static void EnsureInitialized() {}
[OutSystems.HubEdition.RuntimePlatform.MetaInformation.EntityAttributeDetails("Name", 50, false, false, false, false)]
[System.Xml.Serialization.XmlElement("Name")]
private string _ssName;
public string ssName {
get {
return _ssName;
}
set {
if ((_ssName!=value) || OptimizedAttributes[0]) {
ChangedAttributes[0] = true;
_ssName = value;
}
}
}

[OutSystems.HubEdition.RuntimePlatform.MetaInformation.EntityAttributeDetails("Amount", 50, false, false, false, false)]
[System.Xml.Serialization.XmlElement("Amount")]
private string _ssAmount;
public string ssAmount {
get {
return _ssAmount;
}
set {
if ((_ssAmount!=value) || OptimizedAttributes[1]) {
ChangedAttributes[1] = true;
_ssAmount = value;
}
}
}


Can someone help?



Solution

Hi Waqas

Paste your code here please, the code that sets the values in BenDet and the code that adds the record to your output list.


Victor

Solution

I was having trouble with null references in my objects once before because I discovered I needed to put "null" as an argument to the constructors of my response structures. For whatever reason, the objects were being instantiated with null attributes without it, but if I had it then they would be instantiated with empty values corresponding to how OutSystems interprets "null." There is an article describing these "null" values across all different primitive data types in OutSystems, hold on I will find it.

Hi Waqas,

The code you copy/pasted is internal code that initializes Records in the Extension. They are very likely not the cause of your exceptions. You should focus on your own code. Like Victor says, without that code it's difficult to tell what goes wrong.


Victor Salvalagio Pereira wrote:

Hi Waqas

Paste your code here please, the code that sets the values in BenDet and the code that adds the record to your output list.


Victor

Here is my code


public void MssBEN2(string ssRefNo, out RLBenDetRecordList ssBenDetails) {
            RCBenDetRecord rec = new RCBenDetRecord();
            ssBenDetails = new RLBenDetRecordList();
           
           
           

            rec.ssENBenDet.ssName = "WAQAS"; (When i am setting value of variable, it is giving error)
            rec.ssENBenDet.ssAmount = "10";
            rec.ssENBenDet.ssStatus = "ACTIVE";

            ssBenDetails.Add(rec);
// TODO: Write implementation for action
} // MssBEN2


Kilian Hekhuis wrote:

Hi Waqas,

The code you copy/pasted is internal code that initializes Records in the Extension. They are very likely not the cause of your exceptions. You should focus on your own code. Like Victor says, without that code it's difficult to tell what goes wrong.



Here is my code

public void MssBEN2(string ssRefNo, out RLBenDetRecordList ssBenDetails) {
            RCBenDetRecord rec = new RCBenDetRecord();
            ssBenDetails = new RLBenDetRecordList();
           
           
           

            rec.ssENBenDet.ssName = "WAQAS";
            rec.ssENBenDet.ssAmount = "10";
            rec.ssENBenDet.ssStatus = "ACTIVE";

            ssBenDetails.Add(rec);
// TODO: Write implementation for action
} // MssBEN2



BenDet is an entity (from an external database) or it's a structure?
I'm asking this because the code from my extension is different from yours. My prefix for ssENBenDet is ssSTBenDet, and I have a structure, and not an entity.

Did you try instantiate ssENBenDet before the assign?

I don't have any code here using entities to compare...

Victor Salvalagio Pereira wrote:


BenDet is an entity (from an external database) or it's a structure?
I'm asking this because the code from my extension is different from yours. My prefix for ssENBenDet is ssSTBenDet, and I have a structure, and not an entity.

Did you try instantiate ssENBenDet before the assign?

I don't have any code here using entities to compare...

Its a structure...


Yes i tried to initiate ssENBenDet but still error.


public void MssBEN2(string ssRefNo, out RLBenDetRecordList ssBenDetails) {
            RCBenDetRecord rec = new RCBenDetRecord();
            ssBenDetails = new RLBenDetRecordList();



            rec.ssENBenDet = new ENBenDetEntityRecord();
            rec.ssENBenDet.ssName = "WAQAS";
            rec.ssENBenDet.ssAmount = "10";
            rec.ssENBenDet.ssStatus = "ACTIVE";

            ssBenDetails.Add(rec);
// TODO: Write implementation for action
} // MssBEN2

I think depending on structure attributes, Bit Array is defined by auto generated code and before setting attribute value, that bit array is null and value is not been set. :(

Hi Waqas,

If you initialize a Record (as opposed to a Record List), you need to specify a parameter, to avoid the default constructor being called. This can be null. Grayson already mentioned this above. So your statement should be:

 rec.ssENBenDet = new ENBenDetEntityRecord(null);

If you omit the "null", the Structure's Attributes aren't initialized.

That said, why is the Amount Attribute a Text instead of an Integer or Decimal?

Kilian Hekhuis wrote:

Hi Waqas,

If you initialize a Record (as opposed to a Record List), you need to specify a parameter, to avoid the default constructor being called. This can be null. Grayson already mentioned this above. So your statement should be:

 rec.ssENBenDet = new ENBenDetEntityRecord(null);

If you omit the "null", the Structure's Attributes aren't initialized.

That said, why is the Amount Attribute a Text instead of an Integer or Decimal?

Thanks for your help. It resolved my issue. 


yes amount i will change it to decimal. I was trying all the things to make it simple. This was first extension i was trying to create from my external databases.


Thanks all for help.