Follow

DOC - Delete draft after adding a document

Important Notes

The samples and information below is provided without a warranty of any kind. This post is for informational purposes and coresystems ag assumes no responsibility for errors or omissions in the information provided.


Purpose

Attached is 1 customize optimizer rule that will ask the user every time when he adds a marketing document that is based on draft document if he wants to delete the draft document. When selcting "Yes" the draft document will be deleted from the draft table. When selecting "No" the draft will exist afterwards as usual.

 

Requirements

The sample requires coresuite Version 3.50 or higher, and SAP Business One 8.8 or higher.


Procedure to use this small solution

  1. Download the attached file FAQ_10149_Delete_draft_documents_after_adding_document.cocu
  2. Import in SAP Business One via > Administration > Add-Ons > coresuite customize > Import / Export > Import rules. In the message box, select “All Active”. Click on “Import”.
To check the rule in action (sample invoice document):
  1. Save a new A/R Invoice as a draft
  2. Open the new draft from the Document Drafts Report (> Sales - A/R > Sales Reports > Document Drafts Report > Select the Checkbox A/R Invoice > OK)
  3. Add the A/R Invoice Draft
  4. In the System Message box "Do you want to delete the Draft?" select "Yes".
  5. Open again the Document Drafts Report and see that the draft does not exist anymore.


Procedure to adjust this small solution

The rule works for all standard marketing documents for sales and purchasing without any adjustments required. The message is in English always and could be translated to other relevant languages.

Preview Sample (Optimizer Rule C#):


string ruleName = pVal.RuleInfo.RuleName;
string errorMessage = "Error in Optimizer Rule '" + ruleName + "'";
string QUERY = "";
try
{
string DOCENTRY = pVal.BusinessObjectKeyString;
switch (pVal.Form.Type)
{
case "133":
case "60090":
case "60091":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM OINV T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "179":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM ORIN T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "140":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM ODLN T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "180":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM ORDN T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "139":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM ORDR T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "149":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM OQUT T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "141":
case "60092":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM OPCH T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "181":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM ORPC T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "143":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM OPDN T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "182":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM ORPD T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "142":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM OPOR T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "540000988":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM OPQT T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "721":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM OIGN T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
case "720":
{
QUERY = @"SELECT TOP 1 T0.[draftKey] FROM OIGE T0 WHERE T0.[DocEntry] = " + DOCENTRY;
break;
}
default:
return true;
}

using(System.Data.SqlClient.SqlDataReader rdr = customize.B1Connector.GetB1Connector().ExecuteQuery(QUERY))
{
if (rdr.HasRows)
{
rdr.Read();
if (!(Convert.IsDBNull(rdr["draftKEY"])))
{
int DRAFTKEY = Convert.ToInt32(rdr["draftKey"]);
if (MessageBox.Show("Do you want to delete the Draft ?", "Yes", "No", MessageBox.Buttons.Button2) == MessageBox.Buttons.Button1)
{
SAPbobsCOM.Documents pDraft = (SAPbobsCOM.Documents) SwissAddonFramework.B1Connector.GetB1Connector().Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);
pDraft.GetByKey(DRAFTKEY);
pDraft.Remove();
StatusBar.WriteSucess("Draft Document has been deleted.");
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(errorMessage + ": \n" + ex.Message, "OK");
StatusBar.WriteError(errorMessage + ": " + ex.Message);
Debug.WriteMessage(errorMessage + ": " + ex.Message, Debug.DebugLevel.Exception);
}
GC.Collect();
return true;
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.