Can some one please help me with this code snippet?

I am running this code as a script task in a business process.

string POid = Get<string>("PurchaseOrderID");
var arParts = POid.Split('_');
 
 
		int i = Convert.ToInt32(arParts[1]);
		int newid = i + 1;
		string prefix = string.Empty;
		if(newid<10){
			prefix="00000";
		}
		else if (newid<100)
		{ prefix="0000";
		}
		else if (newid<1000)
		{
			prefix="000";
		}
		else if (newid<10000)
		{
			prefix="00";
		}
		else if (newid<100000)
		{
			prefix="0";
		}
 
		string intstringid = newid.ToString();
		string name = prefix + intstringid; 
		string newPOid = "PO_" + name;
		Set("NewPurchaseOrderID", newPOid);
return true;

I have "PurchaseOrderID" and "NewPurchaseOrderID" as the parameters that I've defined for this business process. They are spelled as in the code, I've checked that.

 

When I try to run this process, I get the error: Object reference not set to an instance of an object.

 

Can't seem to find which object I have not initiated.

 

Any help would be appreciated.

 

Thanks.

-AK

Like 0

Like

1 comments

It seems that  "PurchaseOrderID"  parameter has no value, so in the following row

var arParts = POid.Split('_')

the error "Object reference not set to an instance of an object" occurs because POid is null. To know for sure please debug the code. The article by the link below will be helpful in that: https://academy.bpmonline.com/documents/technic-sdk/7-13/server-code-debugging

Show all comments