I am attempting to programmatically create a vendor comment in the FORM_OnAfterTransaction(data) event of AP10.1. On pages 105-106 of the Lawson Design Studio User Guide version 10 (LDSUG_10.0.9.0_UWA.pdf) there is an example for exactly what I want to do. The problem is that it's not a working example. It looks like it's creating an Invoice comment, not a Vendor comment because it references Invoice data fields that aren't available to AP10. Here is their example:
function FORM_OnAfterTransaction(data) { // was transaction successful? if (formState.agsError) return;
// grab the value for the select box var vList = lawForm.getFormValue("select12"); if (vList != "None") addComment(vList); }
function addComment(vList) {
//Case for the four options var vAudt switch (vList) { case "All": vAudt="A"; break; case "Report": vAudt="D"; break; case "Note": vAudt="N"; break; case "Check": vAudt="C"; break; } // set variables from the form to use in API var vComm=lawForm.getFormValue("textarea1"); vCompany = lawForm.getDataValue("API-COMPANY"); vVendor = lawForm.getDataValue("API-VENDOR"); var vInvoice=lawForm.getFormValue("text12"); vTitle = portalWnd.oUserProfile.getAttribute("lawsonusername");
// build the API call for the writeattach cgi s = portalWnd.WRITEATTACHPath + "?_OUT=XML&_PDL=" + strPDL; s += "&_FN=APINVOICE&_IN=APISET1&K1=" + vCompany; s += "&K2=" + vVendor; s += "&K3=" + vInvoice; s += "&K4=000&K5=0000&_ATYP=C&_AUDT=" + vAudt; s += "&_USCH=none&_DATA=TRUE&_OPM=M&_ECODE=FALSE&_ANAM=" + vTitle; s += "&_ATXT=" + vComm;
// send API to the server portalWnd.httpRequest(s);
// Reset the Textarea and set the select to None var space=""; lawForm.setFormValue("textarea1",""); lawForm.setFormValue("select12","None"); }
You can see it gets data from API-COMPANY and API-VENDOR which are not AP10 data fields. Here is what I am doing (have some debugging code in there for now):
Here is my call to the addVendorComment function below:
addVendorComment(vendorCompany,sVendorfld,"","D","OFAC","OFAC CHECK COMPLETED PAYEE INFO NOT A MATCH TO WLE.");
function addVendorComment(vendorCompany,vendor,locationCode,commentType,commentTitle,comment){
/* This function will add a vendor comment. */
/* build the API call for the writeattach cgi */ s = portalWnd.WRITEATTACHPath + "?_OUT=XML&_PDL=" + strPDL; s += "&_FN=APCOMMENTS&_IN=APCSET1"; s += "&K1=V"; s += "&K2=" + vendorCompany; s += "&K3=" + vendor; s += "&K4=" + locationCode; s += "&K5=0000&_ATYP=C&_AUDT=" + commentType; s += "&_USCH=none&_DATA=TRUE&_OPM=M&_ECODE=TRUE"; s += "&_ANAM=" + commentTitle; s += "&_ATXT=" + comment;
alert("s=" + s); // For debugging /* send API to the server */ var addCmnt = portalWnd.httpRequest(s); alert("HTTP Request complete"); // For debugging
if (!addCmnt || addCmnt.status) { // error retrieving file: display message var msg="Error adding " + commentTitle + " comment."; if (addCmnt) msg+=("\n"+portalWnd.getHttpStatusMsg(addCmnt.status)); portalWnd.cmnDlg.messageBox(msg,"ok","stop",window); return; }
alert("Checking error message"); // For debugging var addCmntErrMsg = addCmnt.selectSingleNode("//ErrMsg").text; alert("Error message: " + addCmntErrMsg); // For debugging
}
The last "alert" displays "Error message: Invalid value for User Defined Type: _AUDT=(D)."
I opened an incident with Lawson support and pointed out the example in their documentation doesn't work and is incorrect but they told me I would need to contact professional services since it was a customization. Apparently they don't care that their documentation is wrong.
Has anyone been able to successfully generate a vendor comment programmatically or can you see any obvious errors with my code?
Thanks, Randy
I've made some progress but it's not necessarily good news. The "Parent Record not Found" message wasn't referring to the vendor record but rather the parent comment record. I guess it makes sense. When creating a vendor comment in AP12.1 you first create the comment record (the "Parent") and then click the "Comments" button next to the comment you just added and then add the detail. When you create the parent comment a sequence number is generated. When I placed that sequence number in the fifth key field (&K5=0001) of my writeattach call it was successful.
I'm not sure if it's possible to do what I want to do. Unless I can create that parent record first and get the sequence number that was generated I'm out of luck. Maybe an AGS call first. I will play with it.
In the example from the manual the comment is being added to the APINVOICE table. The Vendor comments are actually attachments to the APCOMMENTS table rather than the APVENMAST table so yes you would need to do an ags/Transaction call to AP12 first and then the writeattachrec call.
make sense?
AP12 is a little funky... You need to also populate LINE-FCr0=A and APC-PRINT-CODEr0= whatever value you want for that field (A,D,C,N) depending on your needs.
Then when you run your command it will return an xml document that will have the Sequence number populated.
Also if you are going to be adding more comments for the same vendor it will get a little more complicated.
Jason,
Thank you for the insight! I was able to get it working by adding the two fields you included. I had to add a DME call to get the current number of comments so I could determine which line number to use in the line and print code fields. Using 0 is fine if there are no other comments for that vendor but if the vendor already has comments you need to determine which detail line is next. And of course if the number of existing comments is 14 or more (meaning you're no longer on the first page of comments) you have to keep subtracting 14 from that number until you have a number less than 14. Once I got that figured out I was able to add a comment. The sequence is as follows:
1. Get the current number of comments using a DME call.
2. Add the parent comment using an AGS call to AP12.1.
3. Add detail to the parent comment using writeattachrec.
It's a little convoluted but gets the job done. Thanks again for your help!