Trying to run a code page from Formula URL via Formula Rich Text

  • 0
  • 1
  • Question
  • Updated 4 weeks ago
  • In Progress
I want an image button that runs a codepage (OTP.js).  I'm fairly new to all this so bear with me.  I have set up my code page which prompts the user for information (re questing a number) this then runs the API_EditRecord.  I have called the code page this from my URL button....no problem.  I'm trying to now have an image button (using a rich text field) call this URL button.  I have done a lot of seaching on here and have found that this might be best way to accomplish. (if not please let me know). 

Here is my Rich text formula: (image shows but nothing happens when clicked)
var text Image=URLRoot() & "/up/bn7siaqwg/g/r6/eh/va/plus.png";
"<a href='"& [Add Primary OTP] &"'> <img height=40 src=" & $image & "></a>"

Here is my URL formula: this field is called [Add Primary OTP]
"javascript:" & "var QBU_rid = '" & [Record ID#] & "';" & "$.getScript('" & URLRoot() & "/db/" & Dbid() & "?a=dbpage&pagename=OTP.js');" & "void(0);"

Here is my Script Page code:
(function(){
var OTP = prompt("Please Enter the Primary OTP#:","Numeric and 11 Digits");
document.location.href="myURLhere?a=API_EditRecord&rid="+QBU_rid+ "&_fid_41="+OTP;
})();
 Note myURLhere is a place holder.

I have also tried calling code page directly from the Rich text formula with no luck. If there is a better way OR if you see an error in my code or methodolgy please let me know and remember I'm fairly new at Javascript my only exposure to it is here in QB.  TIA for all the support. 

On a side note I have tried mutliple ways to redirect back to the original page but doesn't seem to work with the href in the code page (found the original code here). If anyone has some tips on that subject I'm all ears.
Photo of Gregory Gebhardt

Gregory Gebhardt

  • 70 Points
  • a little frusterated

Posted 4 weeks ago

  • 0
  • 1
Photo of Everett Patterson

Everett Patterson

  • 966 Points 500 badge 2x thumb


Where are you wanting the button to be placed for the users? On a form?


You should be able to use the IOL technique, and call on the code page that contains all those functions (I.E. user prompt, API edit record, onclick handler, page redirect). Trying to force all those functions through the native formula fields can be tough.