AnsweredAssumed Answered

Code throws exception where attribute has "is Configuration set" = true.  Why?

Question asked by Koerkel on Jun 15, 2017
Latest reply on Jun 15, 2017 by Koerkel

I am trying to run through some code to check a value of an attribute.  If the attribute is "0" (zero), then set it to 1.  Code works good until I came across one element where the attribute was set to "Is Configuration Item". 

Code throws exception on the line I am setting variable "myvalue".

 

Why?

What is this "Is Configuration Item"?

How can I remove the "Is Configuration Item"?

I'm not sure how the "Is Configuration Item" was set to true for this one element.

 

Here is code section:

 

                        var elements = AFElement.FindElements(database, null, meter, AFSearchField.Name, true, AFSortField.Name, AFSortOrder.Ascending, 1000);

                        if (elements.Count >= 1)

                        {

                            foreach (var element in elements)

                            {

                                intCTPTValue = element.Attributes["CTPTRatios"].GetValue(); 

                                myvalue = (float) intCTPTValue.Value;  // throws exception here for attribute where "Is Configuration Item" set to true.

                                if (myvalue == 0)

                                {

                                    intCTPTValue = new AFValue("1");

                                    element.Attributes["CTPTRatios"].SetValue(intCTPTValue);

                                }

Outcomes