Pandora - Sample - Create Transaction Link to Level 1 Record

From SmartWiki
Jump to: navigation, search

The following script is run when a pop-up window is used to create a new transaction via a link on the Level 2 activity.

Because the Transaction must exist in the database before the intersection table (translink) can be created, it runs onload. It won't run when the pop-up first appears, since the transid will be 0, but once the user saves the record and the page reloads the transaction link will be created when the page loads after saving.

It obtains a value (cf_1741979) from the Level 2 activity form that initiated the new transaction pop-up and stores that value on the link between the Level 1 and the Transaction which is created by this script.


This script exists on a Browser Script custom field on the Transaction type.

</script>
<script type="text/javascript" language="javaScript" src="/Ajax/uta/uta.js"></SCRIPT>
<script language="javaScript">

var oldonload = window.onload;
if (typeof window.onload != 'function')   window.onload = newonload;
else {
    window.onload = function() {
          oldonload();
          newonload();
     }
}

function newonload(){

//ensure there is an opener page (otherwise this transaction was not opened as a pop-up:
if(!opener) return;
var frm=opener.document.frmevent;

if(!frm) return;  //ensure the opening page was a level 2 in edit mode:

var yearelement=frm.cf_1741979;
var poppidelement=frm.fd_objectid;  //if this was loaded from a Level 2 Template Page
if(!poppidelement) poppidelement=frm.objectid;   //if this was not a Template Page
var tfrm=document.frmtrans;   //the current form (Transaction form)

//ensure all the necessary elements are present, 
//and that this transaction is in the database (transid.value!=0)
if((yearelement && poppidelement && tfrm) && tfrm.transid.value!=0){
    var year=yearelement.value;
    var poppid=poppidelement.value;

    ss_developer_key="abcdefgjijklmnopqurstvwxyz1234567890=";
    var rs=new ssRecordSet(null);
    rs.addfieldnames('cf_1741624');  //Store the value from the L2
    var idx=rs.getnewrecnumber();
    rs.addfieldvaluebyname(idx,'cf_1741624',year);
    
    //create the link:
    translink_add(false,"",0,tfrm.transid.value,poppid,23,rs);
    }
}