Can I use a code page to insert a file into a record?

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered
I have a field in my record that creates a pop-up window to my code page.

"https://mypage.quickbase.com/db/bj25sdevd?a=dbpage&pageID=17\"  onclick=\"window.open('https://mypage.quickbase.com/db/bj25sdevd?a=dbpage&pageID=17', 'newwindow', 'width=500, height=200'); return false;\"> Add Signature"


My code page then allows the user to draw their signature using jQuery jSignature. What I want to do is save this image that is saved by the javscript, and insert it into another field in that record. Possible? Here's part of my code page:

function importImg(sig)

{

sig.children("img.imported").remove();

var file = $("<img class='imported'></img>").attr("src",sig.jSignature('getData'));

    qdb.EditRecord(qdb.dbid, field["Record ID#"], ["Signature File", file]);



}

This doesnt work by the way. It works up to the point of getting the image file from the their signature, then I can't get it into the attachment field.
Photo of Jacob

Jacob

  • 0 Points

Posted 4 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
I may have done this in the past for a client - I honestly can't remember. But in any case that library can return the signature image as a dataurl string. A dataurl string is can be saved in a text field. To see what a dataurl string looks like go to this site:

DATAURL Generator
http://dopiaza.org/tools/datauri/index.php

and enter the URL of this image (QuickBase logo)

C:\Users\reference\Desktop\intuit_logo.gif

The dataurl will show up in the text input after "Your data: URI is:"

So see how to use this dataurl look at the attached HTML document named intuit_logo.html and you will see that it has an <img> tag with the src set to the dataurl string that the above service returned.

So all you have to do is save the dataurl jSignature returns in a text field an write a short text formala with some HTML allowed to generate the <img> markup.

If you need additional help beyond this description feel free to contact me using the contact info in my profile.
Photo of Jacob

Jacob

  • 0 Points
Thank you so much! I think this method will work.
I know this is amateur, but I am having trouble passing a variable in my javascript code page to a field in a quickbase table so that I can use the formula text field to format it this way. Do I use API? It seems to me that because I am already within quickbase I would not need to use an API.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
>I know this is ...

Well I subscribe to the "See One, Do One, Teach One" learning method used by medical students so there is no need to be self-deprecating. See:

http://spin.atomicobject.com/2011/04/29/see-one-do-one-teach-one-not-just-for-the-medical-profession/

But that said I can't make any sense of your statement: "I am having trouble passing a variable in my javascript code page to a field in a quickbase table so that I can use the formula text field to format it this way". I need to see your existing code to give you some advice. I don't have the time to create a self contained demo of this. Also I see you are using the JavaScript QuickBase Client library:

qdb.EditRecord(...

I would advise you not to use it because it is 2015 not 1995.
Photo of Jacob

Jacob

  • 0 Points
After some reading online, I have stopped using the javascript SDK.
To rephrase, my problem is this. I have the variable fileUrl obtained with this code:
var fileUrl = sig.jSignature('getData','base30');

This variable contains the dataUrl of the signature image. I need to place that data into a record within my application. Would this be accomplished using the API_EditRecord? Or is there a better way to do that?

Also, even if I use the API, I don't have the Record ID of the record I need to edit. Is there a way to pass that record# to my code page when someone clicks on the link to my code page within a record?

The reason I didn't post code is because I don't have exsisting code! This was one attempt, but it didn't work.

xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","https://my_domain/db/main?a=API_Authenticate&username=username&password=password&hours=24",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

var ticket = $(xmlDoc).find("ticket").text();
var token = "token";

xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","https://my_domain/db/main?a=API_EditRecord&rid=[Record ID#]&_fid_66="+fileUrl+"&ticket="+ticket+"&apptoken="+token,false);
xmlhttp.send();