Add an activity with attachment to a Service Call when the Service Call is added
Paolo Manfrin
The attached customize rule add an attachment to an activity and link such activity to a service call when the service call is added in SAP Business One.
The code inside the customize rule is the following:
try
{
string contractPath = "C:\AttachmentFolder\Sample_Contract.pdf";
StatusBar.WriteSucess("Add activity");
string callID = SwissAddonFramework.Utils.SQL.ExecuteQueryScalar("SELECT TOP 1 CallID FROM OSCL ORDER BY CallID Desc").ToString();
SAPbobsCOM.Company comp = SwissAddonFramework.B1Connector.GetB1Connector().Company;
SAPbobsCOM.ServiceCalls oSC = (SAPbobsCOM.ServiceCalls) comp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oServiceCalls);
SAPbobsCOM.Contacts activity = (SAPbobsCOM.Contacts) comp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oContacts);
oSC.GetByKey(Convert.ToInt32(callID));
activity.Activity = SAPbobsCOM.BoActivities.cn_Note;
//string callType = SwissAddonFramework.Utils.SQL.ExecuteQueryScalar("SELECT Name FROM OSCT WHERE callTypeID = '" + oSC.CallType.ToString() + "'").ToString();
activity.Details = "Service Call: " + callID + " - Contract";
activity.Notes = "Service Call: " + callID + " - Contract";
activity.CardCode = oSC.CustomerCode;
// Add attachment to activity
int countAttachments = activity.Attachments.Count;
activity.Attachments.Add();
activity.Attachments.Item(countAttachments).FileName = contractPath;
int errCode = activity.Add();
if(errCode != 0)
{
string errMsg = comp.GetLastErrorDescription();
StatusBar.WriteError(errMsg);
Debug.WriteMessage(errMsg, SwissAddonFramework.Messaging.Debug.DebugLevel.Always);
}
else
{
string activityID = comp.GetNewObjectKey();
int activityRow =Convert.ToInt32(SwissAddonFramework.Utils.SQL.ExecuteQueryScalar("SELECT COUNT(ClgCode) FROM OCLG WHERE parentType = '191' AND parentId = '" + callID + "'"));
oSC.Activities.Add();
oSC.Activities.SetCurrentLine(activityRow);
oSC.Activities.ActivityCode = Convert.ToInt32(activityID);
errCode = oSC.Update();
if(errCode != 0)
{
string errMsg = comp.GetLastErrorDescription();
StatusBar.WriteError(errMsg);
Debug.WriteMessage(errMsg, SwissAddonFramework.Messaging.Debug.DebugLevel.Always);
}
else
{
StatusBar.WriteSucess("Activity created - " + activityID);
}
}
}
catch (Exception ex)
{
StatusBar.WriteError(ex.Message);
}
return true;
hth
paolo
Sebastian Hagen
Works fine, thanks Paolo...
I think this rule has something related on you camel case, hah! :rolleyes:
0
-
Thanks for sharing it Paolo.
How can I get the object of an existing activity linked to a service call?
activity
I want to create a function button rule to add an attachment to an existing activity.
Thanks in advance,
Sebastian
0
Please sign in to leave a comment.
Comments
1 comment