Error Opening InsertOpportunity.aspx in SalesLogix 7.2 Web

I posted this a while back in the SalesLogix Business Partner newsgroups, but it has recently just helped a few others who came across it there, so I thought it would be a worthwhile public post. Not everyone will get the error mentioned in this post, but if you are then this should help. This post also describes my troubleshooting process to locate this issue and determine the fix for it.

I have a customer who could not bring up the Insert New Opportunity Screen. After stepping through things with VS I determined that I was getting an error in the GetOppProductDefaults business rule on the Opportunity entity. The GetOppProductDefaults method looks like this (as seen through reflector):

public static void GetOppProductDefaults(IOpportunity opportunity)
{
string commonOption = ApplicationContext.Current.Services.Get<IUserOptionsService>().GetCommonOption("Products", "OpportunityDefaults");
if (commonOption != "")
{
commonOption = commonOption.Substring(commonOption.IndexOf("<rs:data>")).Replace("rs:data>", "rsdata>").Replace("z:row", "zrow").Replace("</xml>", "");
XmlDocument document = new XmlDocument();
try
{
document.LoadXml(commonOption);
foreach (XmlNode node in document.SelectSingleNode("rsdata").ChildNodes)
{
if (node.Attributes["PRODUCTID"].Value != null)
{
IOpportunityProduct item = EntityFactory.Create<IOpportunityProduct>();
item.Opportunity = opportunity;
item.Product = EntityFactory.GetById<IProduct>(node.Attributes["PRODUCTID"].Value);
item.Sort = new int?(Convert.ToInt32(node.Attributes["SORT"].Value));
item.Program = node.Attributes["PRICELEVEL"].Value;
item.Price = new decimal?(Convert.ToDecimal(node.Attributes["PRICE"].Value));
item.Discount = new double?(Convert.ToDouble(node.Attributes["DISCOUNT"].Value));
item.Quantity = new double?(Convert.ToDouble(node.Attributes["QUANTITY"].Value));
item.ExtendedPrice = new decimal?(Convert.ToDecimal(node.Attributes["EXTENDED"].Value));
opportunity.Products.Add(item);
}
}
}
catch (Exception)
{
throw new Exception("Invalid xml for default Opportunity Products");
}
}
}

The stack trace from the exception showed the following:

   at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at System.String.Substring(Int32 startIndex)
at Sage.SalesLogix.Opportunity.Rules.GetOppProductDefaults(IOpportunity opportunity)
at Sage.SalesLogix.Opportunity.Rules.CheckOppAccount(IOpportunity opportunity, Boolean& result)
at (Object )
at Sage.Platform.DynamicMethod.DynamicMethodLibrary.Execute(String methodName, Object[] args)

You’ll notice that the exception was thrown from the attempt to use Substring on a string within the GetOppProductDefaults method. The Substring is used to get only the XML between the <rs:data></rs:data> tags from the serialized XML from the Recordset stored there, ignoring the schema data from the beginning section of the XML. So, I looked and this is what this customer has stored there for *all* users for the Products in the OpportunityDefaults user option:

<xml xmlns:z="#RowsetSchema" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly" rs:updatable="true">
<s:AttributeType name="SORT" rs:number="1" rs:write="true">
<s:datatype dt:type="int" dt:maxLength="4" rs:precision="0"
rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="PRODUCTID" rs:number="2" rs:write="true">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="12"
rs:precision="0" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="KEYFIELDID" rs:number="3" rs:write="true">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="16"
rs:precision="0" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="PRODUCT" rs:number="4" rs:write="true">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="64"
rs:precision="0" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="FAMILY" rs:number="5" rs:write="true">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="64"
rs:precision="0" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="PRICELEVEL" rs:number="6" rs:write="true">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="32"
rs:precision="0" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="PRICE" rs:number="7" rs:write="true">
<s:datatype dt:type="number" rs:dbtype="currency" dt:maxLength="8"
rs:precision="0" rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="DISCOUNT" rs:number="8" rs:write="true">
<s:datatype dt:type="float" dt:maxLength="8" rs:precision="0"
rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="ADJPRICE" rs:number="9" rs:write="true">
<s:datatype dt:type="number" rs:dbtype="currency" dt:maxLength="8"
rs:precision="0" rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="PRICELOCAL" rs:number="10" rs:write="true">
<s:datatype dt:type="number" rs:dbtype="currency" dt:maxLength="8"
rs:precision="0" rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="QUANTITY" rs:number="11" rs:write="true">
<s:datatype dt:type="float" dt:maxLength="8" rs:precision="0"
rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="EXTENDED" rs:number="12" rs:write="true">
<s:datatype dt:type="number" rs:dbtype="currency" dt:maxLength="8"
rs:precision="0" rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
<s:AttributeType name="EXTENDEDLOCAL" rs:number="13"
rs:write="true">
<s:datatype dt:type="number" rs:dbtype="currency" dt:maxLength="8"
rs:precision="0" rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
<s:extends type="rs:rowbase"/>
</s:ElementType>
</s:Schema>

</xml>

There is no <rs:data> section in this XML, so obviously, that is why the use of Substring is failing, because the IndexOf is returning an invalid integer for a start position. Normally, in any other system I’ve checked so far, this XML is completely blank for users that have never set any defaults. For a user that goes into the dialog to set the defaults and clicks OK without selecting any default products they will have the XML, but an empty <rs:data> section. Empty is OK, because at least it exists and the code above will not fail.

So, I have no idea what caused the XML to get saved this way in the first place. I will continue to look for this in other systems, but I wanted to mention all this here in case others run into this. This is all fixed by having these users simply go into the Opportunity Defaults dialog (in the fat client) and just clicking OK. This will cause the empty <rs:data> section to be added to the XML for the serialized recordset and then all wil work fine.

I was originally going to suggest that the code for the GetOppProductDefaults be changed to check the IndexOf the “<rd:data>” section frst before proceeding to get the Substring. This certainly would have saved me some headache since the code would not have completely crapped out for this customer – but I have no idea how this got stored this way for this customer in the first place, so no telling how common this scenario would be. The weird thing is that the XML is like this for *all* users for my customer. This was an upgrade BTW, but so was my own internal database and it doesn’t have this problem.

The Solution

For now, just have your users go to the Set Opportunity Defaults screen in the Windows client and just open and close (by clicking OK) the opportunity products default screen (they don’t actually have to select any product defaults). This will cause the proper XML string to be saved for that user. Optionally, you could programatically store the corrected XML for them.

I’ve not checked yet to see if this business rule has been fixed for 7.5 or not.

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. Hi Ryan, we had this exact problem with an individual user in SLX Web 7.5. When we tried your solution the user also got an error when going into Set Opportunity Defaults –> Products. The solution for our particular user was to run the following SQL against the databse incase it helps anyone else – DELETE FROM USEROPTIONS WHERE USERID = ‘user id’.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!