Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Monday, August 3, 2020 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix .NET Extensions
Forum to discuss the use of .NET Extensions in SalesLogix version 7 and higher. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix .NET Extensions | New ThreadView:  Search:  
 Author  Thread: Add Opportunity Attachment
Vaughn Poulson
Posts: 32
 
Add Opportunity AttachmentYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 May 15 3:46 PM

I have vbscript code to add an attchment to an opportunity.  I'm using the same fields and functions in .net but it's not attaching.


Here is the vbscript code:


 Dim attachId, size

    attachId = Application.BasicFunctions.GetIDFor("ATTACHMENT")

    'copy the file to the attachment folder

    Dim filesys, Fs, attachDesc

    Set filesys = CreateObject("Scripting.FileSystemObject")

    If filesys.FileExists(Form.tbSaveTo.Text & Form.tbFileName.Text & ".pdf") Then

        Set Fs = filesys.GetFile(Form.tbSaveTo.Text & Form.tbFileName.Text & ".pdf")

        On Error Resume Next

        Fs.Copy(Application.BasicFunctions.GetAttachmentPath & "!" & attachId & Form.tbFileName.Text & ".pdf")

        If Err.Number <> 0 Then

            MsgBox "Error Saving The Attachment" & vbCRLF & "Description: " & Err.Description & vbCRLF & "Source: " & Err.Source, vbOKOnly + vbCritical, "ERROR"

            Err.Clear

            Exit Sub

        End If

        'insert new record in the attachment table

        size = Fs.Size

        Dim objAttchRs, strSql

        Set objAttchRs = slxDb.GetNewRecordSet

        strSql = "Select * From Attachment Where 1=2"

        objAttchRs.Open strSql, slxDb.Connection

        objAttchRs.AddNew

        attachDesc = "Proposal #" & Form.tbOppNumber.Text

        If Trim(Form.tbVersion.Text) <> "" Then

            attachDesc = attachDesc & "-" & Form.tbVersion.Text

        End If

        attachDesc = attachDesc & CStr(Date)

        attachDesc = Replace(attachDesc, "/", "-")

        objAttchRs.Fields("ATTACHID").Value = attachId

        objAttchRs.Fields("ATTACHDATE").Value = Date

        objAttchRs.Fields("OPPORTUNITYID").Value = Form.tbOppId.Text

        objAttchRs.Fields("DESCRIPTION").Value = attachDesc

        objAttchRs.Fields("DATATYPE").Value = "R"

        objAttchRs.Fields("FILESIZE").Value = size

        objAttchRs.Fields("FILENAME").Value = "!" & attachId & Form.tbFileName.Text & ".pdf"

        objAttchRs.Fields("USERID").Value = Application.BasicFunctions.CurrentUserID

        objAttchRs.Update

        Set objAttchRs = Nothing

        Application.BasicFunctions.UpdateFileAttachment attachId

        Application.BasicFunctions.LogSendFileAttachment Application.MainViews.ActiveView.CurrentID, "!" & attachId & Form.tbFileName.Text & ".pdf"

    Else

        MsgBox "Unable to find the specified file to create the attachment."

    end if

 

 

Here is my C# .net code

 

 string filePathAndName = tbPath.Text; 

 if (File.Exists(filePathAndName))                 

{                     

	FileInfo fi = new FileInfo(filePathAndName);                     

	Hoj_SLX_DAL.Attachment.Attachment attachment = new Hoj_SLX_DAL.Attachment.Attachment();                     

	attachment.IsDirty = true;                     

	attachment.ToInsert = true;                     

	attachment.Id = SlxApplication.BasicFunctions.GetIDFor("ATTACHMENT");                     

	attachment.AccountId = string.Empty;                     

	attachment.ActivityId = string.Empty;                     

	attachment.AttachDate = DateTime.Now;                     

	attachment.ContactId = string.Empty;                     

	attachment.ContractId = string.Empty;                     

	attachment.CreateSource = "Test ";                     

	attachment.DataType = "R";                     

	attachment.DefectId = string.Empty;                     

	attachment.Description = string.Empty;                     

	attachment.FileSize = Convert.ToInt32(fi.Length);                     

	attachment.FileName = "!" + attachment.Id + "vpTest.pdf";                     

	attachment.HistoryId = string.Empty;                     

	attachment.UserId = SlxApplication.BasicFunctions.CurrentUserID();                     

	attachment.OpportunityId = OpportunityId;                     

	attachment.Save(SlxApplication.ConnectionString);                      

	SlxApplication.BasicFunctions.UpdateFileAttachment(attachment.Id);                     

	SlxApplication.BasicFunctions.LogSendFileAttachment(SlxApplication.MainViews.ActiveView.CurrentID, attachment.FileName);                 

}                 

else   

{                     

	MessageBox.Show("Cannot Find The File " + filePathAndName, "SalesLogix", MessageBoxButtons.OK, MessageBoxIcon.Information);                 

}

Not sure what i'm missing.



 

[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Add Opportunity AttachmentYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 May 15 3:54 PM

I don't see anywhere in the .NET code where you are actually copying the file (unless that is happening in the Hoj_SLX_DAL.Attachment.Attachment class or something)

[Reply][Quote]
Vaughn Poulson
Posts: 32
 
Re: Add Opportunity AttachmentYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 19 May 15 8:38 AM

I had totally missed that.  Thanks Ryan it now works.

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2020 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 8/3/2020 12:19:42 PM