GetSaleDocuments renders no results

lock
push_pin
done
Answered
4

Hi,
I am running below code. It does not give any results. Even though the sale has documents.

CRMScript:

NSDocumentAgent documentAgent;
NSDocument[] saleDocuments = documentAgent.GetSaleDocuments(SALEID);

printLine(saleDocuments.length().toString());
for(Integer i = 0; i < saleDocuments.length(); i++) {

String documentUrl = documentAgent.GetDocumentUrl(saleDocuments[i].GetDocumentId(), "", true);
printLine(documentUrl);
}

C#

var documentAgent = new DocumentAgent(config);
var saleDocuments = await documentAgent.GetSaleDocumentsAsync(saleId);



What am I doing wrong? NSDocument[]  and  saleDocuments are empty in both cases. 

 

The Sale has documents:

25 May 2023 | 10:41 AM

All Replies (4)

Hi John,

I believe those are only documents that have been linked to the sale via the Links tab on a Sale. Using CRMScript, you can use the archive agent to search for the documents you want based on the saleId. Here is an example:

NSArchiveRestrictionInfo[] restrictions;
NSArchiveRestrictionInfo res1;
res1.SetName("sale/saleId");
res1.SetOperator("=");
res1.SetValues(String("35").split(","));
restrictions.pushBack(res1);

NSArchiveOrderByInfo[] order;
 
String[] entities = String("document").split(",");

Integer pageSize = 250;

NSArchiveAgent archiveAgent;
NSArchiveListItem[] rows = archiveAgent.GetArchiveListByColumns("simpledocument", String("documentId,sale/saleId").split(","), order, restrictions, entities, 0, pageSize);

foreach (NSArchiveListItem row in rows)
{
  Map rowData = row.GetColumnData();
  Integer documentId = decodeDBValue(rowData.get("documentId")).toInteger();
  Integer saleId = decodeDBValue(rowData.get("sale/saleId")).toInteger();
  printLine("Processing document with id '" + documentId.toString() + "'");
}

Hope this helps!

25 May 2023 | 12:59 PM

Hi,

Thank you for swift answer.

The Documents were added by New -> Document and adding them to the Sale

So they are added to the Sale. They fit the definition of the function:

Or how do you add documents to a sale that you can get by using GetSaleDocuments? 

 

25 May 2023 | 01:08 PM

Hi John,

Actually no, the way you added the documents does not fit the definition of the function.

Linking a document to a sale is done via the Sale Links tab.

Adding a document (creating a document entity) and having it appear as a document activity is not the same thing as a Linked document.

Hope this helps.

 

 

25 May 2023 | 01:17 PM

Hi,

Thank you for clearing that out! 

I will do some tests. 

Have a nice weekend!

 

26 May 2023 | 02:36 PM

Add reply