Help with Merge to Word Coding

SOLVED

Hi.

I'm using this code to display a Merge to Word button within an ASP file:

if( CRM.Mode == 2) {
if(true){
searchContainer.AddButton(CRM.Button("ButtonMailMerge", "NewDoc.gif", "javascript:document.EntryForm.TargetAction.value = 'NewWordDocument'; document.EntryForm.submit();"));
}

However, its not working quite right when it comes to storing the mail merge it within the companies' communication that follows.An unexpected event has occurred: EOleException: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

I think it has to do with the Button. But I'm not 100% sure. 
Can someone let me know if the coding above is legit for Sage CRM v2018r3?

Thanks,

Stephan

  • +1
    verified answer

    You can find example code within the XXXXXLibrary.asp page that the Advanced Customization Wizard generates.

    var caption = "FileUpload";
    // The "FILEUPLOAD" string below is NOT  a CAPTION - it is a constant to indicate to the COM object that a FILEUPLOAD button is expected
    caption = "FILEUPLOAD";
    Container.AddButton(CRM.Button(caption, "FileUpload.gif", CRM.URL(343)+"&Key-1="+iKey_CustomEntity+PersonKey+CompanyKey+OpportinityKey+HasCommunication+"&PrevCustomURL="+List.prevURL+"&E=Project"));

    Container.DisplayButton(1)=false;
    if (true){
      Container.AddButton(CRM.Button("MergeToWord", "MailMergeDOC.gif", CRM.URL(542)));
      Container.AddButton(CRM.Button("MergeToPDF", "MailMergePDF.gif", CRM.URL(6101)));
    }
  • 0 in reply to Sage CRM

    Good Morning.

    I tried what you sent - however, I keep getting the following error:

    You must be in the context of a main entity if you want to create a new merge document. Open a record before clicking Start Mail Merge. Once you have done this, you can select or create a document to merge.

    542 - is probably the issue.
    What is the Act number for a SearchContainer?

    Let me know,

    Thanks,

    Stephan

  • 0 in reply to stephenLan

    Hmm.

    I checked and 542 is the correct ACT number to use after running this query:

    select * from custom_captions
    where capt_family = 'ActionNames'
    and capt_familytype = 'Tags'
    and capt_us not like 'Sage CRM%'
    order by capt_code desc

    ---

    Now I have no clue why this error is appearing: "You must be in the context of a main entity if you want to create a new merge document. Open a record before clicking Start Mail Merge. Once you have done this, you can select or create a document to merge."

    I think I have no choice but to use  "javascript:document.EntryForm.TargetAction.value = 'NewWordDocument'; document.EntryForm.submit();"));

    Let me know your thoughts on this.

    Stephan

  • +1 in reply to Sage CRM
    verified answer

    Hi.

    I think I found the issue I'm having.
    It has to do with the &Key0=58

    This needs to be &Key0=19 instead.

    How do I make this change with the following code:"javascript:document.EntryForm.TargetAction.value = 'NewWordDocument'; document.EntryForm.submit();")); 

    Or with this code:searchContainer.AddButton(CRM.Button("MergeToWord", "MailMergeDOC.gif", CRM.URL(542)));

    Let me know.

    Thanks,

    Stephan

  • 0 in reply to stephenLan

    All good.

    I figured out what was missing in my query in order for it to work properly.

    Thanks for your assistance.

    Stephan

  • 0 in reply to Sage CRM

    Hi Jeff,

    Is there a way to run a Mail Merge for a specific document template in an ASP page.

    The full flow would then include saving to the library and emailing this document to the Person on the record or a specific User. 

    Any guidance would be greatly appreciated!

    Stephanie