DME calls within a form
Scenario: You are a new customer who wants to use the Lawson Asset Management product. Your assets have pre-assigned alphanumeric identifiers.
Problem: Lawson uses Asset as the main key and it is numeric. Tag number is alphanumeric but is not a key. You do not want to make back-end program changes.
Solution: Hide the asset field and use your existing tag number. When a user tabs away from the tag field, this script runs. The script looks in the database for the matching asset number, and puts it in the asset field.
Later, you can add a new index to the AMASSET table. The index has TAG and ASSET as keys in that order. This makes record-filtering faster than it is with a DME SELECT statement as used below.
function TEXT_OnBlur(id, row)
{
// if it's not the field we're interested in, quit
if (id !== "out3")
{
return true;
}
// build the DME call that will get the related asset number
const vDmeString = "?PROD=" + strPDL + "&FILE=AMASSET&FIELD=ASSET" +
"&SELECT=TAG-NBR=" + vTag + "&MAX=1&OUT=XML";
// send the DME call to the server
const vDMEInfo = portalWnd.httpRequest(portalWnd.DMEPath + vDmeString);
if (!vDMEInfo || vDMEInfo.status)
{
let msg = "Error calling DME, ";
msg += (vDMEInfo
? "(status code): " + vDMEInfo.status
: "bad server response.");
portalWnd.cmnDlg.messageBox(msg);
return true;
}
// create an XML object to contain the DME data
const vObjDMEXML = new portalWnd.DataStorage(vDMEInfo);
// load a variable with the value returned by DME
const vRecord = vObjDMEXML.getElementCDataValue("COL",0);
if (!vRecord)
{
portalWnd.cmnDlg.messageBox("No assets found matching this tag number.");
return true;
}
lawForm.setElementValue("text1", vRecord);
return true;
}