Files
Mareon/ax/SRC/A2012_UploadDocument.js
Marcel Bourseau 7aacebd7e5 MARX#61048: Documenten versturen van Mareon naar AX (Stadgenoot)
svn path=/Mareon/trunk/; revision=46490
2020-04-03 14:45:55 +00:00

99 lines
3.4 KiB
JavaScript

// --------------------------------------------------------------------------------------
// A2012_UploadDocument.js
// Copyright 2020 SG|facilitor. 053-4800 700, helpdesk@mareon.nl
// Written by MB (2020)
//
function A2012_UploadDocument (v_base64_str)
{
var v_API = "api/v0.2/UploadDocumentFileBase64";
var l_json_data =
{
base64: v_base64_str
}
var v_req = JSON.stringify(l_json_data, null, 2);
var v_type = 0;
var v_soapAction = "";
var v_discard_active_abort = 1; //In geval van 500-error, geen active abort...
var v_resp = api_AX2(v_API, v_req, v_type, v_soapAction, v_discard_active_abort);
//Response v_resp is iets als dit:
//{
// "checksum": "ouWe2rfVjQXRItrYVAh8zBLgXkK33c3fTvsW7eUaXJc1"
//}
return v_resp;
}
function A2012_GetCheckSum_UploadDocument(p_json_text){
v_checksum = "";
if (p_json_text){
p_json = eval("(" + p_json_text + ")");
v_checksum = p_json.checksum;
}
__Log("A2012_GetCheckSum_UploadDocument v_checksum: " + v_checksum, 3);
return v_checksum;
}
// v_company_id, unieke id van (interne) bedrijf
// v_entityname, b.v. ServiceTask of PurchaseOrder, in dit geval altijd op nivo van PurchaseOrder
// v_entityid, b.v. MLD15009954-01 (Servicetask) of ION123456 (PurchaseOrder)
// v_checksum, een reeks (string) die AX via A_UploadDocument teruggeeft, en hier moet worden gebruikt.
// v_filename, naam van het te uploaden bestand, b.v test.png
// v_description, omschrijving van het bestand
// v_notes, een bijbehorende notitie.
function A2012_CreateDocuRefByEntityName (v_company_id, v_entityname, v_entityid, v_checksum, v_filename, v_notes)
{
var v_API = "api/v0.1/" + v_company_id + "/DocumentReferences";
var l_file_without_ext = MARX_substr(v_filename,".",1);
var l_json_data =
{entityName: v_entityname,
entityId: v_entityid,
documentReference:
{name: l_file_without_ext,
notes: v_notes,
docuTypeId: "Mareon",
fileName: v_filename,
checksum: v_checksum
}
}
//Voorbeeld:
// {"entityName": "ServiceTask",
// "entityId": "MLD15009954-01",
// "documentReference":
// {"name": "omschrijving van het testbestand",
// "notes": "notitie",
// "docuTypeId": "Mareon",
// "fileName": "Testbestand.png",
// "checksum": "fGd0DavlPXvhM6wVgHM-zpSGM7R0h8q9xJkIzf3leIk1"
// }
// }
var v_req = JSON.stringify(l_json_data, null, 2);
var v_type = 0;
var v_soapAction = "";
var v_discard_active_abort = 1; //In geval van 500-error, geen active abort...
var v_resp = api_AX2(v_API, v_req, v_type, v_soapAction, v_discard_active_abort);
//Hieronder is een voorbeeld van de bericht body te zien
// {"entityName": "ServiceTask",
// "entityId": "MLD15009954-01",
// "documentReference": {"name": "Voorbeeld.txt",
// "notes": "Voorbeeld via webservice",
// "docuTypeId": "Bestand",
// "filename": "Voorbeeld.txt",
// "checksum": "89N3v4fkPjSQ5IgkZSEmou6GOjOdiUPRBfFC5tseejI1" } }
return v_resp;
}