Follow

Coding examples for coresuite time API

DI Operations

Connect coresuite time API from an external project

//include the DLL's SWA_CT.dll, SWA_CT_DI.dll and SwissAddonFramework.dll
SwissAddonFramework.B1Connector.GetB1DIOnlyConnector("sapusername", "sappassword", "licenseserver:30000", SAPbobsCOM.BoSuppLangs.ln_German, "sqlserver", SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008, "companydb", out errCode);
SWA_CT.StartOnlyDI.Intitialize();
SWA_CT_DI.Global.SetMode(SWA_CT_DI.Global.Modes.DI);
SWA_CT_DI.Global.RegisterTimeObjects();
SWA_CT_DI.Global.EnableCompatibiltyMode();
SWA_CT_CloudConnector.Logic.Synchronization.GetInstance().StartSynchronization();

Add project

SWA_CT_DI.Logic.Project project = new SWA_CT_DI.Logic.Project();
project.BusinessPartnerObject = new SWA_CT_DI.Logic.BusinessPartner("cardCode");
project.Subject = "subject";
project.Save();

Add effort

SWA_CT_DI.Logic.Effort effort = new SWA_CT_DI.Logic.Effort();
effort.Resource = new SWA_CT_DI.Logic.Resource("resourceCode");
effort.TimeObject = new SWA_CT_DI.Logic.ServiceCall("callID");
foreach (SWA_CT_DI.Logic.Task taskObj in SWA_CT_DI.Logic.Task.GetTasks(effort.TimeObject, effort.Resource))
{
      effort.Task = taskObj;
      break;
}
effort.StartTime = new TimeSpan(8, 0, 0);
effort.EndTime = new TimeSpan(9, 0, 0);
effort.Date = DateTime.Today;
effort.Save();

Add expense

SWA_CT_DI.Logic.Effort baseEffort = new SWA_CT_DI.Logic.Effort("Code of an existing effort");
SWA_CT_DI.Logic.EffortCharges expense = new SWA_CT_DI.Logic.EffortCharges(baseEffort);
expense.Charges = new SWA_CT_DI.Logic.Charges("Effort type code");
SWA_CT_DI.Logic.Amount externalAmount = new SWA_CT_DI.Logic.Amount();
externalAmount.BaseAmount = 100.0; /*external amount in local currency*/
expense.AmountExternal = externalAmount;
expense.Save();

Add worktime

SWA_CT_DI.Logic.WorkTime worktime = new SWA_CT_DI.Logic.WorkTime();
worktime.Resource = new SWA_CT_DI.Logic.Resource("resourceCode");
worktime.StartTime = new TimeSpan(8, 0, 0);
worktime.EndTime = new TimeSpan(9, 0, 0);
worktime.Date = DateTime.Today;
worktime.Save();

Add special condition on a sales order

SWA_CT_DI.Logic.SpecialItem specialItem = new SWA_CT_DI.Logic.SpecialItem();
specialItem.TimeObject = new SWA_CT_DI.Logic.DocSalesOrder("docEntry");
specialItem.EffortType = new SWA_CT_DI.Logic.EffortType("effortTypeCode");
specialItem.Description = "Special Item Description";
specialItem.Save();

Billing Wizard V1: Change document just before it gets added

SWA_CT.Events.Document.ChangeDocumentEvent += delegate(SAPbobsCOM.Documents document)
{
     //example 1: change NumAtCard with own reference
     document.NumAtCard = "1234567";

     //example 2: change business partner of the document
     document.CardCode = "C10000";

     //example 3: remove discounts on the lines if the base document is a service call
     for(int i = 0; i < document.Lines.Count; i++)
     {
           document.Lines.SetCurrentLine(i);
           
          //return if line is referenced to something else than service call
          if(document.Lines.UserFields.Fields.Item("U_SWA_CT_BType").Value.ToString() != "191"/*service call*/)
                return;

          document.Lines.DiscountPercent = 0;
     }
};

Billing Wizard V2: Change document just before it gets added

COR_BillingWizard.Logic.BillingWizard.BillingWizardEvents.OnBeforeDocumentAdd += delegate(SAPbobsCOM.Documents document)
{
     //example 1: change NumAtCard with own reference
     document.NumAtCard = "1234567";

     //example 2: change business partner of the document
     document.CardCode = "C10000";

     //example 3: remove discounts on the lines if the base document is a service call
     for(int i = 0; i < document.Lines.Count; i++)
     {
           document.Lines.SetCurrentLine(i);
           
          //return if line is referenced to something else than service call
          if(document.Lines.UserFields.Fields.Item("U_SWA_CT_BType").Value.ToString() != "191"/*service call*/)
                return;

          document.Lines.DiscountPercent = 0;
     }
};

 

How to exclude a certain Business Partner from the list of objects to invoice, displayed by the Billing Wizard.

COR_BillingWizard.Logic.BillingWizard.BillingWizardEvents.OnGetBillableObjects += delegate(ref System.Collections.Generic.IEnumerable<COR_BillingWizard.Logic.BillingWizard.IRow2> objects)
{
    System.Collections.Generic.List<COR_BillingWizard.Logic.BillingWizard.IRow2> filtered = new System.Collections.Generic.List<COR_BillingWizard.Logic.BillingWizard.IRow2>();

    foreach (var row in objects)
    {
        if (row.CardCode != "C23900")
        {
            filtered.Add(row);
        }
    }

    // replace the original list with the filtered list
    objects = filtered;
};

 

Time recording: Change Charges before they get added. This also works similarly with other types like Efforts. The steps can also be used to interact with objects synchronized from the Cloud

SWA_CT_DI.Customization.GetInstance().LogicObjectBeforeSave += delegate(SWA_CT_DI.Logic.LogicObject lgo)
{

       if (lgo.GetType().ToString() == "SWA_CT_DI.Logic.EffortCharges")
       {
              SWA_CT_DI.Logic.EffortCharges eff = (SWA_CT_DI.Logic.EffortCharges) lgo;

              //change distance of Charges with own value

              eff.Distance = 2.0;

       }

};

 

UI Operations

Add new effort to a time project and open time recording form

SWA_CT_DI.Logic.Project timeObject = new SWA_CT_DI.Logic.Project("projectCode");
SWA_CT_SAP.UI.Forms.TimeRecording.GetInstance(SWA_CT_UI.Forms.Main.MainForm.TABS.DETAILED).AddNewEffort(timeObject);

Disable tab on time recording form

SWA_CT_UI.Customization.GetInstance().EnableTab += delegate(SWA_CT_DI.Logic.User user, string tabName)
{
       if(tabName=="tab_journal") /*tab_journal, tab_worktime, tab_detailed, tab_weekly also available*/
             return false;
       else
             return true;
};

Open existing subscription

SWA_CT.View.FormObjects.FormObject.ShowObject("SWA_CT_SUBSCR"/*object type*/, "9"/*object code*/);

Modify the Internal Description based on the linked object

/*This example checks the object linked to an effort. When the object is a service call and the service call has a contract template linked to it then the "Internal Description" is populated with the contract template name.*/

SWA_CT_UI.Customization.GetInstance().CheckEffortOnCreateEffortOnDetailedViewBeforeOpenRemarks += delegate(SWA_CT_DI.Logic.Effort effort)
{
       try
       {
              if(!(effort.TimeObject is SWA_CT_DI.Logic.ServiceCall))
              return true;

              string code = effort.TimeObject.Code;
              string query = @"SELECT T0.contractID, ISNULL(T1.[CntrcTmplt],'') AS [ContractTemplateName]
                                             FROM OSCL T0 LEFT JOIN OCTR T1 ON T0.contractID = T1.ContractID
                                             WHERE T0.callID = " + code + "";

              using(System.Data.SqlClient.SqlDataReader rdr = SwissAddonFramework.B1Connector.GetB1Connector().ExecuteQuery(query))
              {
                     if (rdr.Read())
                     {
                            string contractTemplateName = rdr["ContractTemplateName"].ToString();
                            if (!string.IsNullOrEmpty(contractTemplateName))
                            {
                                   effort.InternalDescription = "[Contract: " + contractTemplateName + "]";
                            }
                     }
              }
       }
       catch (Exception innerException)
       {
              StatusBar.WriteError(innerException.Message);
              Debug.WriteMessage("Inner Error on rule " + pVal.RuleInfo.RuleName + ":" + innerException.Message, SwissAddonFramework.Messaging.Debug.DebugLevel.Exception);
       }
       return true;
};

Define for which TimeObjects effort can be recorded (in Extended Object Search)

/*This code defines which TimeObjects can be used for time recording. All wanted objects can be added to the list.*/
SWA_CT_DI.Customization.GetInstance().TimeObjectList += delegate(System.Collections.Generic.List<SWA_CT_DI.Logic.TimeObject> lst)
{
      System.Collections.Generic.List<SWA_CT_DI.Logic.TimeObject> newLst = new System.Collections.Generic.List<SWA_CT_DI.Logic.TimeObject>();
      newLst.Add(new SWA_CT_DI.Logic.ServiceCall());
      newLst.Add(new SWA_CT_DI.Logic.Project());
      newLst.Add(new SWA_CT_DI.Logic.BusinessPartner());
      return newLst;
};

 

Billing Wizard V2: Change properties of 3rd screen

/*This code is able to modify the properties of the 3rd screen of the billing wizard v2 such as document type, series, draft*/
COR_BillingWizard.Logic.BillingWizard.BillingWizardEvents.OnSummary += delegate(System.Collections.Generic.IEnumerable<COR_BillingWizard.Logic.BillingWizard.ISummaryLine> summary)
{
      foreach (COR_BillingWizard.Logic.BillingWizard.ISummaryLine sl in summary)
      {
            sl.TargetObjectIsDraft = true; //set target document by default as draft
      }
};

Was this article helpful?
2 out of 2 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.