Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a manufacturing order using the API

Status
Not open for further replies.

dboukhira

Programmer
Dec 14, 2004
8
CA
Hello,

System: MISYS 5.0 - Accpac Advantage series 5.2.

The manufacturing header is created but the materials and the routings are not copied in the MO.

Any help appreciated.

Public Function SaveMO(ByVal strCompany As String) As String

Dim Connection As New SqlConnection(Global.ConnStr)
Dim drItem As SqlDataReader
Dim strSQL As String
Dim command As New SqlCommand(strSQL, Connection)

Dim oSession As AccpacCOMAPI.AccpacSession
Dim AccpacDBLink As AccpacCOMAPI.AccpacDBLink
Dim sUsername As String
Dim sPassword As String

Dim iTransactionLevel As Integer
Dim SysLink As AccpacCOMAPI.AccpacDBLink
Dim intErrCount As Integer

Dim temp As String
Dim strID As String

Dim rc As tagViewReturnCode

Dim oFPUtils As New FPUtils

Connection.Open()

strSQL = "SELECT Manufacturing_Order_Headers.* FROM Manufacturing_Order_Headers "
strSQL &= "WHERE 1=1 "
command.CommandType = CommandType.Text
command.CommandText = strSQL
drItem = command.ExecuteReader()


'**********************************
' On établit la connection à Accpac
'**********************************
sUsername = oFPUtils.GetCompanyUsername(strCompany)
sPassword = oFPUtils.GetCompanyPassword(strCompany)

System.GC.Collect()
System.GC.WaitForPendingFinalizers()

oSession = New AccpacCOMAPI.AccpacSession
Try
oSession.Init("", "SM", "SM0000", "52A")
Catch err As Exception
temp = err.Message
oSession.Close()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
SaveMO = temp
Exit Function

Finally
End Try

Try
oSession.Open(sUsername, sPassword, strCompany, System.DateTime.Today, 0, "")
Catch err As Exception
temp = err.Message
oSession.Close()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
SaveMO = temp
Exit Function

Finally
End Try

AccpacDBLink = oSession.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_COMPANY, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)

Dim MIGLOB1 As AccpacCOMAPI.AccpacView
Dim MIGLOB1Fields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0008", MIGLOB1)
MIGLOB1Fields = MIGLOB1.Fields

MIGLOB1.Init()
MIGLOB1.Browse("", 1)
MIGLOB1.Fetch()

Dim MIMOHheader As AccpacCOMAPI.AccpacView
Dim MIMOHheaderArray(2) As AccpacCOMAPI.AccpacView
Dim MIMOHheaderFields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0046", MIMOHheader)
MIMOHheaderFields = MIMOHheader.Fields

Dim MIMOHdetail As AccpacCOMAPI.AccpacView
Dim MIMOHdetailArray(2) As AccpacCOMAPI.AccpacView
Dim MIMOHdetailFields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0047", MIMOHdetail)
MIMOHdetailFields = MIMOHdetail.Fields

Dim MIMORD As AccpacCOMAPI.AccpacView
Dim MIMORDArray(2) As AccpacCOMAPI.AccpacView
Dim MIMORDFields As AccpacCOMAPI.AccpacViewFields
AccpacDBLink.OpenView("MI0065", MIMORD)
MIMORDFields = MIMORD.Fields

MIMOHheaderArray(0) = MIMOHdetail
MIMOHheaderArray(1) = MIMORD
MIMOHheader.Compose(MIMOHheaderArray)

MIMOHdetailArray(0) = MIMOHheader
MIMOHdetailArray(1) = Nothing
MIMOHdetail.Compose(MIMOHdetailArray)

MIMORDArray(0) = MIMOHheader
MIMORDArray(1) = Nothing
MIMORD.Compose(MIMORDArray)

Try
While drItem.Read()
MIMOHheader.Init()

MIMOHheaderFields.Item("WOHID").Value = drItem("WOHID") ' Order No.
MIMOHheaderFields.Item("ITEM").Value = drItem("ITEM") ' Assembly No.
MIMOHheaderFields.Item("DESCR").Value = drItem("DESCR") ' Description
MIMOHheaderFields.Item("LOC").Value = "LOC01" ' Location
MIMOHheaderFields.Item("STARTDATE").Value = Now().Date ' Start Date
MIMOHheaderFields.Item("ENDDATE").Value = Now().Date ' Completion Date
MIMOHheaderFields.Item("HDRTX1").Value = drItem("HDRTX1") ' ABC
MIMOHheaderFields.Item("HDRTX2").Value = drItem("HDRTX2") ' Couverture
MIMOHheaderFields.Item("ORDERQTY").Value = drItem("ORDERQTY") ' Required Quantity

MIMOHheaderFields.Item("CREATOR").Value = "SYSTEM"
MIMOHheaderFields.Item("RELEASDATE").Value = Now().Date
MIMOHheaderFields.Item("RELEASER").PutWithoutVerification("ADMIN") ' Released By
MIMOHheaderFields.Item("MOSTAT").Value = "1"
MIMOHheaderFields.Item("PRSTAT").Value = "4"

MIMOHheader.Post()
MIMOHheader.Process()
MIMOHheader.Insert()
rc = MIMOHheader.LastReturnCode

MIMOHdetail.Post()
MIMOHdetail.Process()
rc = MIMOHdetail.LastReturnCode


End While

Catch err As Exception
' Annuler la transaction
AccpacDBLink.TransactionRollback(iTransactionLevel)
intErrCount = oSession.Errors.Count
Dim j As Integer
For j = 0 To intErrCount - 1
SaveMO = "Erreur:" & oSession.Errors.Item(j)
Next

Finally
MIMOHdetail.Close()
MIMOHheader.Close()
MIMORD.Close()
MIGLOB1.Close()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
oSession.Close()
command.Dispose()
drItem.Close()
Connection.Close()

End Try


End Function
 
Because you only inserted a header. You have to insert details, too!

Jay Converse
IT Director
Systemlink, Inc.
 
The MO header should retrieve the BOM details and insert them as details.
I suspect you need to remove or move the MIMOHheader.Post() and MIMOHdetail.Post() lines, they look out of place.

This is a long shot, but try changing
MIMOHheader.Post()
MIMOHheader.Process()
MIMOHheader.Insert()
rc = MIMOHheader.LastReturnCode

MIMOHdetail.Post()
MIMOHdetail.Process()

to
MIMOHheader.Process()
MIMOHdetail.Process()
MIMOHheader.Insert()
MIMOHheader.Post() 'I don't know if .Post ir required here


 
My first code included only the insert and the process methods.

I added the Post line after, hopefully that I will get the materials and the routings copied in the MO.

I tried many combinations like:
Insert, Process
Process, Insert
Insert, Process, Post
Post, Insert, Process etc...

No results. I feel tired to do gambling programming (-

Thanks for any help.
 
Run RVSPY to see how Misys does it.

Jay Converse
IT Director
Systemlink, Inc.
 
Just to change the Order quantity and click on the save button, it generated hundreds of lines.

RVSPY output is not readable.
 
In RVSpy, I choose Options, Output and specify MIMOMD2 in the File field but I could'nt find the file generated (I did a search)
 
I toyed with this yesterday and there is a whole heap of stuff Misys performs behind the scenes, which is kindly not recorded by the macro recorder. I suspect this functionality is not part of the MO views, so you may have to go off and read the BOM and pupolate the material details in the MO yourself.
Have you tried speaking to Misys? They are normally helpfull chaps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top