Skip to content

Instantly share code, notes, and snippets.

@dallin
Last active April 17, 2020 19:15
Show Gist options
  • Save dallin/c797290968969961b44d8cd9a51d8886 to your computer and use it in GitHub Desktop.
Save dallin/c797290968969961b44d8cd9a51d8886 to your computer and use it in GitHub Desktop.
Open a new window to add QB record, then close the window when the changes are saved
// This snippet will pop up a window (with specified size) to add
// a record, then close the window when the changes are saved.
// Use: in a Formula URL field
var text attachAddressToParentRecordUrl = URLRoot()&"db/"&Dbid()&"?a=API_EditRecord&rid="&[Record ID#]
& "&usertoken=" & "b4pjvn_m6mu_bdjdqxauri75jbrvmm5csns4vh"
& "&apptoken=" & "cm3s4ptbfj6gchcsmr4t3x3228u"
& "&_fid_33=";
var text addAddressWindowUrl = URLRoot() & "db/" & "bp2hi954g" & "?a=nwr&_fid_22=" & [Related Patient];
var number addAddressWindowWidth = 950;
var number addAddressWindowHeight = 725;
"javascript:" &
"var addAddressWindowTop = (screen.height - "&$addAddressWindowHeight&") / 2;" &
"var addAddressWindowLeft = (screen.width - "&$addAddressWindowWidth&") / 2;" &
"var addAddressWindow = window.open('"&$addAddressWindowUrl&"', '_blank', 'toolbar=yes,scrollbars=yes,resizable=yes,width="&$addAddressWindowWidth&",height="&$addAddressWindowHeight&",top='+addAddressWindowTop+',left='+addAddressWindowLeft);" &
"if (window.focus) addAddressWindow.focus();" &
"var addRelatedAddressMonitor = setInterval(function(){if(addAddressWindow.location.href != '"&$addAddressWindowUrl&"' && !addAddressWindow.closed){$.post('"&$attachAddressToParentRecordUrl&"'+addAddressWindow.kRid);addAddressWindow.close();clearInterval(addRelatedAddressMonitor);document.location.reload(true);}else if(addAddressWindow.closed){clearInterval(addRelatedAddressMonitor);}}, 1000);" &
"void(0);"
// You can access the RID of the created/edited record by accessing
// addAddressWindow.kRid after the addAddressWindow location has changed back to "view" mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment