Load an employee image to a form and add a checkbox for including a record from another form

In this script, a file containing an image of an employee launches when the employee's HR11 record is opened. The script also shows how you could add a check box to the form to let the user choose to add a record from a different from (in this case, the AP10 form).

function FORM_OnInit() 
{ 
    // set styles for the image control 
    const imgElem = lawForm.getFormElement("image1"); 
    if (imgElem) 
    { 
        lawForm.hide(imgElem); 
        imgElem.style.top = "1%"; 
        imgElem.style.left = "5%"; 
        imgElem.style.width = "45px"; 
        imgElem.style.height = "57px"; 
    } 
} 
 
function FORM_OnAfterTransaction(data) 
{ 
    // was transaction successful? 
    if (formState.agsError) 
    { 
        return; 
    } 
 
    // pad values for Emp and Co with leading zeros 
    let sEmployee = lawForm.getDataValue("EMP-EMPLOYEE", 0); 
    let sCompany = lawForm.getDataValue("EMP-COMPANY", 0); 
    sCompany = portalWnd.strFillChar(sCompany, 5, "left", "0"); 
    sEmployee = portalWnd.strFillChar(sEmployee, 10, "left", "0"); 
 
    // build image URL and set the image control source 
    sEmployee = "P" + sCompany + sEmployee; 
    const sPath = "/lawson/hrnet/images/employees/" + 
        sEmployee + ".jpg" 
 
    let imgElem = lawForm.getFormElement("image1"); 
    if (imgElem) 
    { 
        imgElem.src = sPath; 
        lawForm.show(imgElem); 
    } 
} 
 
function FORM_OnBeforeTransaction(fc) 
{ 
    return (lawForm.getDataValueById("check1") === "1" ? addAP10() : true); 
} 
 
function addAP10() 
{ 
    // build ags api for the ap10 update 
    let s = portalWnd.AGSPath; 
    s += "?_PDL="+ strPDL; 
    s += "&_TKN=AP10.1&_EVT=ADD&_LFN=ALL&_TDS=IGNORE&FC=A"; 
    s += "&VEN-VENDOR-GROUP=1"; 
    s += "&VEN-VENDOR-VNAME=" + lawForm.getDataValue("EMP-FIRST-NAME"); 
    s += " " + lawForm.getDataValue("EMP-LAST-NAME"); 
    s += "&VEN-VEN-CLASS=EMP" 
    s += "&VDR-ADDR1=" + lawForm.getDataValue("EMP-ADDR1"); 
    s += "&VDR-CITY-ADDR5=" + lawForm.getDataValue("EMP-CITY"); 
    s += "&VDR-STATE-PROV=" + lawForm.getDataValue("EMP-STATE"); 
    s += "&VDR-POSTAL-CODE=" + lawForm.getDataValue("EMP-ZIP"); 
    s += "&_OUT=XML&_EOT=TRUE" 
 
    // submit ags call to server 
    let sAGSInfo = portalWnd.httpRequest(s); 
    sAGSInfo = (sAGSInfo ? new portalWnd.DataStorage(sAGSInfo) : null); 
    if (!sAGSInfo || sAGSInfo.status) 
{ 
return false; 
} 
 
    // collect the API return data and extract out certain values for message 
    const sFldNbr = sAGSInfo.getElementValue("FldNbr", 0); 
    const sMsgNbr = sAGSInfo.getElementValue("MsgNbr", 0); 
    const sMessage = sAGSInfo.getElementValue("Message", 0); 
    portalWnd.cmnDlg.messageBox(sFldNbr + ", " + sMessage + ", " + sMsgNbr); 
    return true; 
}