Onloadfunc

From SmartWiki
Jump to: navigation, search

You can use onloadfunc to create a custom Browser Script that runs whenever a record is first opened.

  • This is in place in the UTA at Level 1, Level 2, Level 3 and Invoicing, as well as on Contacts and Accounts
  • It only runs in Edit mode at Level 1, Contacts and Accounts, not in view mode.


Instructions:

Syntax:

function onloadfunc()
   {
    do this
    RunAnotherFunction()
    do that
   }

Important

  • There can only be one onloadfunc on the page. If there are multiple onloadfunc functions defined the system will only run one of them.

If you have an onloadfunc on multiple different User Roles then if a contact happens to have 2 roles that both have a Custom Field with onloadfunc defined you will run into this issue. This can be avoided by creating an Browser Script Custom Field that is visible for all contacts using the User Custom Fields and/or Contact Custom Fields on Global Settings. That Browser Script custom field can have the onloadfunc that will be visible for all users, that will look for other functions defined on various roles to be called:


function onloadfunc{}(
   if(window.employeeOnloadfunc)   //check if there is a function on the page called employeeOnloadfunc
      employeeOnloadfunc();   //call the function if present.
   if(window.applicantOnloadfunc)   //check if there is a function on the page called applicantOnloadfunc
      applicantOnloadfunc();   //call the function if present.
}

Then on the employee role and applicant role create Browser Script fields with those functions. They will be called in turn by the main onloadfunc that the system calls automatically.


See Also