4GL to C# V8 to ERP10 Upgrade

Hello, I am struggling to convert a small piece of 4GL to C# I have used the online converter supplied by Epicor but I no’t know how to get the code to work, I have no C# knowledge.

I currently have a pre processing BPM on SalesOrder.ChangePartNum In Vantage 8.03.410 this looks at 2 fields and if there is data in them displays as a message in the sales order entry screen. I have changed the old UD filed to a new one for ERP10.

Original 4GL Code

find first ttorderdtl no-lock no-error.
if available ttorderdtl then do:
find first part where part.PartNum = ttorderdtl.PartNum no-lock no-error.
If available part then do:
if part.Character02 > " " then do:
{lib/PublishInfoMsg.i &InfoMsg = “part.Character02” }.
if part.PurComment > " " then do:
{lib/PublishInfoMsg.i &InfoMsg = “part.PurComment” }.
END.
END.
END.
END.

Converted C#
Erp.Tables.part part;
var ttorderdtl_xRow = (from ttorderdtl_Row in ttorderdtl
select ttorderdtl_Row).FirstOrDefault();
if (ttorderdtl_xRow != null)
{
part = (from part_Row in Db.part
where part_Row.PartNum == ttorderdtl_xRow.PartNum
select part_Row).FirstOrDefault();
if (part != null)
{
if (string.Compare((string)part[“Character02”] ," “,true)>0)
{
Lib.PublishInfoMsg(“part.Character02”);
if (string.Compare(part.PurComment ,” ",true)>0)
{
Lib.PublishInfoMsg(“part.PurComment”);
}
}
}
}

And the error

Any help would be greatly appreciated.

thank you

Mark

use Ice.Lib.PublishInfoMsg(…)

use Erp.Tables.Part instead of Erp.Tables.part

use ttOrderDtl not ttorderdtl

Many thanks for your reply

I have modified the code as per your instructions, but I am still getting an error.

Also change Db.part to Db.Part, and change ice.lib.publishinomsg to this.PublishInfoMessage(“body of message”, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, “FirstVar”,“SecondVar”);

First var and second var are just placeholders for your message box headers and such but you can r place the body of the message with any string you want.

Great, thank you

I have modified the code as such but am confused as to how to use the First Var and SecondVar.

Erp.Tables.Part part;
var ttOrderDtl_xRow = (from ttOrderDtl_Row in ttOrderDtl
select ttOrderDtl_Row).FirstOrDefault();
if (ttOrderDtl_xRow != null)
{
part = (from part_Row in Db.Part
where part_Row.PartNum == ttOrderDtl_xRow.PartNum
select part_Row).FirstOrDefault();
if (part != null)
{
if (string.Compare((string)part[“PartStatusComments_c”] ," “,true)>0)
{
PublishInfoMessage(“Part.PartStatusComments_c”,Ice.Common.BusinessObjectMessageType.Information,Ice.Bpm.InfoMessageDisplayMode.Individual, “123”,“456”);
if (string.Compare(part.PurComment ,” ",true)>0)
{
PublishInfoMessage(“Part.PurComment”, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, “FirstVar”,“SecondVar”);
}
}
}
}

At the moment it is working like this

If there is data in both Part.PurComment and Part.PartStatusComments_c then both message boxes show, as expected.

If there is only data in Part.PartStatusComments_c then only the message box for PartStatusComments is displayed, as expected.

If there is only data in Part.PurComment then nothing displays, not as expected

In both cases where the message is shown the message is not the data in the actual field
image
image

I can help on Tuesday when I get back, but you have a nesting problem.
Your first if statement checks the length of the purcomment_c field. If this is true, it allows the second if statement to be executed.
Because the second statement is nested within the first, it will neve execute the second statement if the first one doesn’t pass.
Remember the statement inside the if statement only executes if the if condition returns “true”.
As far as the message contents, you are literally writing the string “purcomment” into it. If you want the field value, you will need to do something like part.PurComment.ToString() or part[“PurComment_c”].ToString() in there

Thank you that would be great, as i said I have no c# knowledge so even though I understand the issue with the if statement i don’t understand how to correct it :slight_smile:

We are about to go Live in ERP10 this weekend so I won’t be able to do much now anyway, Tuesday sounds great in between my firefighting users on the GO Live day!!

Best regards

Mark

Let’s touch base on Tuesday then and we’ll get this working. Good luck with go live! :grinning:

1 Like

Mark, here is your code formatted you can see that your Second message box is inside the if-statement of the is PartStatusComments_c if check.

Erp.Tables.Part part;
var ttOrderDtl_xRow = (from ttOrderDtl_Row in ttOrderDtl
		select ttOrderDtl_Row).FirstOrDefault();
if (ttOrderDtl_xRow != null)
{
	part = (from part_Row in Db.Part
	where part_Row.PartNum == ttOrderDtl_xRow.PartNum
	select part_Row).FirstOrDefault();
	if (part != null)
	{
		if (string.Compare((string)part[“PartStatusComments_c”] ," “,true)>0)
		{
			PublishInfoMessage(“Part.PartStatusComments_c”,Ice.Common.BusinessObjectMessageType.Information,Ice.Bpm.InfoMessageDisplayMode.Individual, “123”,“456”);
			if (string.Compare(part.PurComment ,” ",true)>0)
			{
				PublishInfoMessage(“Part.PurComment”, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, “FirstVar”,“SecondVar”);
			}
		}
	}
}

Like Aaron was saying, if you are looking to do your if-statements independently then you should move the second statement be outside of the inner if-statement; your code will then look something like this.

Erp.Tables.Part part;
var ttOrderDtl_xRow = (from ttOrderDtl_Row in ttOrderDtl
		select ttOrderDtl_Row).FirstOrDefault();
if (ttOrderDtl_xRow != null)
{
	part = (from part_Row in Db.Part
	where part_Row.PartNum == ttOrderDtl_xRow.PartNum
	select part_Row).FirstOrDefault();
	if (part != null)
	{
		if (string.Compare((string)part[“PartStatusComments_c”] ," “,true)>0)
		{
			PublishInfoMessage(“Part.PartStatusComments_c”,Ice.Common.BusinessObjectMessageType.Information,Ice.Bpm.InfoMessageDisplayMode.Individual, “123”,“456”);
		}
		
		if (string.Compare(part.PurComment ,” ",true)>0)
		{
			PublishInfoMessage(“Part.PurComment”, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, “FirstVar”,“SecondVar”);
		}
	
	}
}
2 Likes

Hi Sorry for the delay getting back to you both regarding this,

Ken I have used the second set of code and this gives me the prompts when I expect them, thank for this.

Aaron, I can’t get your suggestion to work to bring back the actual data in the fields that I am referencing i just get the field names in the message box.

Try doing this:

Erp.Tables.Part part;
var ttOrderDtl_xRow = (from ttOrderDtl_Row in ttOrderDtl
		select ttOrderDtl_Row).FirstOrDefault();
if (ttOrderDtl_xRow != null)
{
	part = (from part_Row in Db.Part
	where part_Row.PartNum == ttOrderDtl_xRow.PartNum
	select part_Row).FirstOrDefault();
	if (part != null)
	{
		if (string.Compare((string)part[“PartStatusComments_c”] ," “,true)>0)
		{
			PublishInfoMessage(part[“PartStatusComments_c”].ToString(),Ice.Common.BusinessObjectMessageType.Information,Ice.Bpm.InfoMessageDisplayMode.Individual, “123”,“456”);
		}
		
		if (string.Compare(part.PurComment ,” ",true)>0)
		{
			PublishInfoMessage(part.PurComment.ToString(), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, “FirstVar”,“SecondVar”);
		}
	
	}
}

Awesome, works perfectly, many thanks for your help :slight_smile:

1 Like