Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error in plugin to create xml

(0) ShareShare
ReportReport
Posted on by

Hi all

I have a bit of issue with the below code


int i = 0;
foreach (Entity salesorderitem in orderitems.Entities)
{
weborderitems[i] = new WebSalesOrderItemsWebSalesOrderItem();

if (salesorderitem.Contains("lineitemnumber")) weborderitems[i].lv_itemnumber = Convert.ToInt32(((decimal)salesorderitem["lineitemnumber"])).ToString();
if (salesorderitem.Contains("sb_productnumber")) weborderitems[i].product_code = salesorderitem["sb_productnumber"].ToString();
if (salesorderitem.Contains("quantity")) weborderitems[i].quantity = Convert.ToInt32(((decimal)salesorderitem["quantity"])).ToString();
// if (salesorderitem.Contains("discountpercentage")) weborderitems[i].discount_percentage = Convert.ToInt32(((decimal)salesorderitem["discountpercentage"])).ToString();
if (salesorderitem.Contains("extendedamount")) weborderitems[i].total = ((Money)salesorderitem["extendedamount"]).Value.ToString();
if (salesorderitem.Contains("extendedamount")) weborderitems[i].goods = ((Money)salesorderitem["extendedamount"]).Value.ToString();

WebSalesOrderItemsWebSalesOrderItemTexts[] webordertext = new WebSalesOrderItemsWebSalesOrderItemTexts[2];

webordertext[0] = new WebSalesOrderItemsWebSalesOrderItemTexts();
webordertext[0].itemtext_index = "4";
if (salesorderitem.Contains("sb_besjobref")) webordertext[0].itemtext_value = salesorderitem["sb_besjobref"].ToString();
webordertext[1] = new WebSalesOrderItemsWebSalesOrderItemTexts();
webordertext[1].itemtext_index = "3";
if (salesorderitem.Contains("sb_besprodref")) webordertext[1].itemtext_index = salesorderitem["sb_besprodref"].ToString();
weborderitems[i].itemtexts = webordertext;

//units
WebSalesOrderItemsWebSalesOrderItemUnit[] units = new WebSalesOrderItemsWebSalesOrderItemUnit[1];
units[0] = new WebSalesOrderItemsWebSalesOrderItemUnit();
weborderitems[i].unit = units;
i++;

}

It's with the section in red i feel i have missed something. if the second in red isn't there the plugin works fine if the red section is there the plugin doesn't work any ideas what is missing

Kind Regards

Dan 

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Error in plugin to create xml

    This was the issue if the value was null it kicked it out the code now is

    if (salesorderitem.Contains("sb_besjobref")) webordertext[0] = new WebSalesOrderItemsWebSalesOrderItemTexts(); webordertext[0].itemtext_index = "4"; webordertext[0].itemtext_value = salesorderitem["sb_besjobref"].ToString();

                   if (salesorderitem.Contains("sb_besprodref")) webordertext[1] = new WebSalesOrderItemsWebSalesOrderItemTexts(); webordertext[1].itemtext_index = "3"; webordertext[1].itemtext_value = "" + salesorderitem["sb_besprodref"].ToString();

    Many Thanks for your help

    Dan

  • Verified answer
    Daniel Wikell Profile Picture
    2,360 on at
    RE: Error in plugin to create xml

    Hi

    In this line:

    "if (salesorderitem.Contains("sb_besjobref")) webordertext[0].itemtext_value = salesorderitem["sb_besjobref"].ToString();"

    you currently check if "sb_besjobref" is a property that is available. However it looks like you do not check if the actual value of this property is null. When you invoke the ToString method, it will fail if sb_besjobref is null.

    Since your code example does not include how you retrieved the salesorderitem objects I can't say for sure if you used a retrieve-method which automatically excludes the properties when they are null or if you used a method that retrieves all properties even when null. If you used the latter then the missing null-check may indeed be the problem.

  • Community Member Profile Picture
    on at
    RE: Error in plugin to create xml

    Hi Dan,

    It is difficult to understand which line of code is trying to push data to the 3rd party portal. The only line in red that seems to have an impact should be :

    weborderitems[i].itemtexts = webordertext;

    When you suggest the plugin works fine without the code in red, what is the difference when the code in red is included? Are you not receiving any errors at all?

    Lastly, what type of debugging are you using?

  • Community Member Profile Picture
    on at
    RE: Error in plugin to create xml

    Hi 

    There is no error and it seems to run fine but does not push the data to the third party portal we have. Oddly tho if i run the plugin using the section below of the code it works so i think it's something to do with the multiple references.  

    WebSalesOrderItemsWebSalesOrderItemTexts[] webordertext = new WebSalesOrderItemsWebSalesOrderItemTexts[1];

    webordertext[0] = new WebSalesOrderItemsWebSalesOrderItemTexts();
    webordertext[0].itemtext_index = "4";
    if (salesorderitem.Contains("sb_besjobref")) webordertext[0].itemtext_value = salesorderitem["sb_besjobref"].ToString();

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Error in plugin to create xml

    Are you getting any error message or the plugin doesn't trigger at all? Or something else is happing? Also, what is WebSalesOrderItemsWebSalesOrderItem?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans