web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Getting attachment download URL in X++ 'Wrong parameters specified' error occured

(0) ShareShare
ReportReport
Posted on by 378
Hi everyone,

I’m trying to retrieve dowanload attachment URLs of Purchase order and Expenses Reports, I followed this approach but I think there might be something wrong with my code. When I pass parameter values it works in some cases but in other cases I get the following error:
 
Microsoft.Dynamics.Ax.Xpp.ErrorException: 'Wrong parameters specified'
The error occurs on this line:
 
DocumentManagement::getAttachmentPublicUrl(DocuRef::findValue(docRef.ValueRecId));
 
Here is the full code I used:

 
public static List ListAttachments(RefRecId _recId, str _actualCompanyId, TableName _tableName)
{
    str receiptUrl;
    DocuRef docRef;
    List listUrls = new List(Types::String);

    IApplicationEnvironment env = EnvironmentFactory::GetApplicationEnvironment();
    str currentUrl = env.Infrastructure.HostUrl;
    System.Uri currentHost = new System.Uri(currentUrl);

    while select docRef
    where docRef.RefRecId      == _recId
       && docRef.ActualCompanyId == _actualCompanyId
       && docRef.RefTableId    == tableName2Id(_tableName)
    {
       
        receiptUrl = currentHost.ToString() + DocumentManagement::getAttachmentPublicUrl(DocuRef::findValue(docRef.ValueRecId));

        listUrls.addEnd(receiptUrl);
    }

    return listUrls;
}

Can anyone help me figure out what’s wrong with the code ? 
Thanks
I have the same question (0)
  • Martin Dráb Profile Picture
    235,416 Most Valuable Professional on at
    Getting attachment download URL in X++ 'Wrong parameters specified' error occured
    You're making a big mistake by focusing just on the error message and ignoring where it was thrown and why. Then you have no idea what's going and you need to ask others about it, while you have all the tools you need on hand. At André mentioned, you can use the debugger to see what's happening in your code. To see where the error came from, you can simply look at its StackTrace property, or you can stop in the debugger in Info.add() and then look at stack trace.
     
    I believe you'll see that the exeption is thrown in DocuAction.getPublicUrl(). You'll get this exeception when you try to get the public URL for attachments where is doesn't make sense - anything but files. Notes, for example, have no public URL and you'll get an error when you tryt to use that.
     
    You can check add a check like if (docuRef.docuAction() is DocuActionFile) before calling getAttachmentPublicUrl().
  • D365FO Junior-Dev Profile Picture
    378 on at
    Getting attachment download URL in X++ 'Wrong parameters specified' error occured
    Hi @André Arnaud de Calavon  I am getting a different exception: "An exception occurred when invoking the operation  Function getPublicUrl has been incorrectly called"
    For more clarification my goal is to retrieve the list of attachment URLs for a specific Purchase Order or Expense.
  • André Arnaud de Calavon Profile Picture
    296,703 Super User 2025 Season 2 on at
    Getting attachment download URL in X++ 'Wrong parameters specified' error occured
    Hi D365FO Junior Dev,
     
    Have you read your coding yourself thoroughly? You are looping the DocuRef table and the DocumentManagagement::getAttachmentPublicUrl is requiring a DocuRef buffer. The DocuRef::findValue call is then obsolete. You already have the buffer.
     
    Try this:
    public static List ListAttachments(RefRecId _recId, str _actualCompanyId, TableName _tableName)
    {
        str receiptUrl;
        DocuRef docRef;
        List listUrls = new List(Types::String);
    
        IApplicationEnvironment env = EnvironmentFactory::GetApplicationEnvironment();
        str currentUrl = env.Infrastructure.HostUrl;
        System.Uri currentHost = new System.Uri(currentUrl);
    
        while select docRef
        where docRef.RefRecId      == _recId
           && docRef.ActualCompanyId == _actualCompanyId
           && docRef.RefTableId    == tableName2Id(_tableName)
        {
           
            receiptUrl = currentHost.ToString() + DocumentManagement::getAttachmentPublicUrl(docRef);
    
            listUrls.addEnd(receiptUrl);
        }
    
        return listUrls;
    }
    If this doesn't help, I would suggest using the debugger to find out if all variables do have the expected values.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Alireza Eshaghzadeh Profile Picture

Alireza Eshaghzadeh 799 Super User 2025 Season 2

#2
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 757 Super User 2025 Season 2

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 751 Super User 2025 Season 2

Product updates

Dynamics 365 release plans