Symptom
Via DI API or Service Layer, it is not possible to trigger Approval Procedures based on User Queries.
Reproducing the issue
Prerequisite:
Approval Procedures are set up for the document, which is based on the query.
Sample Code:
RetVal = oOrderDoc.GetApprovalTemplates()
If RetVal <> 0 Then
oCompany.GetLastError(RetVal, ErrorMSG)
MsgBox(“Failed : ” & ErrorMSG & ” (” & Str(RetVal) & “)”)
Return
ElseIf (oOrderDoc.Document_ApprovalRequests.Count > 0 And oOrderDoc.Document_ApprovalRequests.ApprovalTemplatesID > 0) Then
oOrderDoc.Document_ApprovalRequests.SetCurrentLine(0)
oOrderDoc.Document_ApprovalRequests.Remarks = “testDI”
End If
The correct information to check that Approval Procedure is in oOrderDoc.Document_ApprovalRequests.ApprovalTemplatesID. If it is triggered, the value should be bigger than 0.
Cause
Limitation
Solution
It is a limitation in the DI API and Service Layer.
The reason why it is not possible to trigger Approval Procedures based on User Queries via DI API and Service Layer is that it is not possible to get the correct value of ApprovalTemplatesID in DI API and Service Layer when the Approval Procedures is based on User Queries.
Note: If you call the function SaveDraftToDocument() on a draft created by an approval procedure based on user query, all approval related information would be lost.