Uploading Documents to the Library with the ASP COM API

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Uploading Documents to the Library with the ASP COM API

  • Comments 6
  • Likes
In Sage CRM if you have created a new custom entity using the Advanced Customization Wizard then you would have had the option to create a libary page for the entity. This provides a straight forward way of allowing documents to be uploaded into the library and associated with the custom entity.

Below is the basic ASP page code that is generated by the wizard.


var sURL=new String( Request.ServerVariables("URL")() + "?" + Request.QueryString ); 
Container=CRM.GetBlock("container"); 
List=CRM.GetBlock("LibraryList"); 
List.prevURL=sURL; 
var Id = Request.Querystring("Events_EventsID"); 
CRM.SetContext("Events", Id); 
Container.AddBlock(List); 
Container.AddButton(CRM.Button("New", "new.gif", CRM.URL(343)+"&Key-1="+iKey_CustomEntity+"&PrevCustomURL="+List.prevURL+"&E=Events")); 
Container.DisplayButton(1)=false; 
if( Id != '') 
{ 
CRM.AddContent(Container.Execute("Libr_EventsId="+Id)); 
} 
CRM.GetCustomEntityTopFrame("Events"); 
Response.Write(CRM.GetPage());


In this case the new entity is called Events. But the key thing to point out here is that a button has been added that calls the action


CRM.URL(343)


You can build you own like this:


var sURL=new String( Request.ServerVariables("URL")() + "?" + Request.QueryString ); 
var NewLibraryButton = CRM.Button('New','new.gif', CRM.Url(343)+"&PrevCustomURL="+sURL);
Comments
  • I create a custom entity uses the Wizard, with a documents tab and the documents upload fine.  The documents upload and they only reference my custom entity, which is exactly what I want.

    I then created a new entity manually, and I copied the library asp code, exactly from the custom entity library tab asp.  I created a library field to reference the ids of my custom entity records.  This made my new document tab available and functional, however it was not working properly.  It was uploading the document and assigning it to the company and opportunity, and not updating the new library id field with my custom entity record id.

    I want this to behave like the functionalit on my custom entity created by the wizard where it only assigns the document to the custom entity.

    All of my references to the new entity are correct in the code, but it still assigns it to Company and Opportunity, which I do not want, and it is not assigning it to the new custom entity record.

    I changed the iKey_CustomEntity variable to just be 58.

    Code is below:

    <!-- #include file ="accpaccrm.js"-->

    <%

    var sURL=new String( Request.ServerVariables("URL")() + "?" + Request.QueryString );

    eWare.GetTabs("OppoSpecTabs");

    Container=eWare.GetBlock("container");

    List=eWare.GetBlock("LibraryList");

    List.prevURL=sURL;

    var Id = new String(Request.Querystring("opsp_opportunityspecID"));

    if (Id.toString() == 'undefined') {

      Id = new String(Request.Querystring("Key58"));

    }

    //'eWare.SetContext("OpportunitySpec", Id);

    Container.AddBlock(List);

    'Container.AddButton(eWare.Button("New", "new.gif", eWare.URL(343)+"&Key-1=58&PrevCustomURL="+sURL+"&E=OpportunitySpec"));

    Container.DisplayButton(1)=false;

    if( Id != '')

    {

     eWare.AddContent(Container.Execute("libr_opportunityspecid="+Id));

    }

    eWare.GetCustomEntityTopFrame("OpportunitySpec");

    Response.Write(eWare.GetPage());

    %>

  • You've commented out the setting of the context.  Had you added the meta data need to allow set context to work?

    CRM.SetContext("TableName", intRecordId);

    SetContext assumes table in CRM database and assumes translations defined as below.

    Entity must have these 3 translation entries in custom_captions table:

    capt_code = NameColumn

    capt_family = Project //Custom Table Name

    capt_familytype = Tags

    capt_us = Proj_name - FieldName is the actual name of the field in the table e.g. description, each language should be completed.

    capt_code = SummaryPage

    capt_family = Project //Custom Table Name

    capt_familytype = Tags

    capt_us = EntitySummary.asp //Actual ASP file name It assumes a summarypage is in a sub folder of CustomPages with same name as entity.

    capt_code = Project //name of table

    capt_family = RecentList

    capt_familytype = Tags

    capt_us = Project

  • I made a view updates but am still experiencing issues.  First I created a sub folder in Custom Pages for the custom entity and copied my pages into it.  I updated the references in CRM to point to the right locations for the asp pages.  The sub folder has the same name as the entity.

    I added the translations referenced as being needed by set context.  My custom entity has the following translations:

    Code: IdColumn

    Family: OpportunitySpec

    Type: Tags

    Translation: opsp_opportunityspecid

    Code: NameColumn

    Family: OpportunitySpec

    Type: Tags

    Translation: opsp_reason

    Code: OpportunitySpec

    Family: OpportunitySpec

    Type: Tags

    Translation: OpportunitySpec

    Code: SummaryPage

    Family: OpportunitySpec

    Type: Tags

    Translation: OppoSpecSummary.asp

    Code: OpportunitySpec

    Family: RecentList

    Type: Tags

    Translation: OpportunitySpec

    Code: OpportunitySpec

    Family: Tables

    Type: Tags

    Translation: OpportunitySpec

    My code for my OppoSpecLibrary.asp is below.  There are two issues.  The first is when I try to save the document I get an error message saying there is a type mismatch on the SetContext line.  It is not picking up an Id value.

    Second, if I hardcode the Id value for testing in the SetContext line and the Container.Execute line, the document is being saved to the company and opportunity which I do not want.  I want it only to save to the custom entity which it isn't saving to at all.  Also after I click new, I believe it is losing the id values because if I save or click cancel, I go back to the my library asp page, but if I click to the summary page, I again get the type mismatch issue because it can't find an id.

    Please let me know what I am missing.  Thanks.

    <!-- #include file ="..\accpaccrm.js"-->

    <%

    var sURL=new String( Request.ServerVariables("URL")() + "?" + Request.QueryString );

    eWare.GetTabs("OppoSpecTabs");

    Container=eWare.GetBlock("container");

    List=eWare.GetBlock("LibraryList");

    List.prevURL=sURL;

    var Id = new String(Request.Querystring("opsp_opportunityspecID"));

    if (Id.toString() == 'undefined') {

     Id = new String(Request.Querystring("Key58"));

    }

    eWare.SetContext("OpportunitySpec",Id);

    Container.AddBlock(List);

    Container.AddButton(eWare.Button("New", "new.gif", eWare.URL(343)+"&Key-1=58&PrevCustomURL="+sURL+"&E=OpportunitySpec"));

    Container.DisplayButton(1)=false;

    if( Id != '')

    {

    eWare.AddContent(Container.Execute("libr_opportunityspecid="+Id));

    }

    eWare.GetCustomEntityTopFrame("OpportunitySpec");

    Response.Write(eWare.GetPage());

    %>

  • Update:

    I correct the mismatch error I was receiving by removing the +sURL+ from the button code and replacing with  List.PrevURL.

    However I am still having my original issue.  The document is still not saving to the custom entity.  It is only saving to the company and opportunity.  The libr_opportunityspecid field remains null when uploading the document.

  • Update:

    What I noticed is that if I put the libr_CustomEntityID field on the new document screen, it will then save properly.  In the entity I have the was built by the Wizard, the library ID field is not on the screen and it saves properly.

    Is there another setting or translation that needs to be added to allow it to save properly (populate the custom entity library ID field) without having the field on screen?

  • Danny

    I can not think of any other setting.  I have looked at my notes and can't see anything that I have overlooked.

    I would look at what is different with the the Request.Form() and Request.QueryString() information.  The Wizard code may have additional or different data.