Call a Microflow from javascript with either string as parameter or image data as image/JPG;base64,string

Is it possible to directly pass a string parameter value from javascript to a Microflow? If yes, can you please guide. I tried as below but didn't work. The microflow is triggered, but the parameter object keeps being empty, I tried to save and commit as suggested  but didn’t worked. can anyone help? Tried Method 1: Method 1: function passStringToMicroflow(stringValue) {{ entity: "Signature.ImageNP", callback: function (obj) { obj.set('ImageNPname', stringValue); object.set('ImageNPname', stringValue);{ params: { applyto: "selection", actionname: "Signature.signMF", guids: [obj.getGuid()], }, }); };; }); }   Tried Method 2: by this even microflow is not triggered.  Method 2 function passStringToMicroflow(stringValue) {{ entity: "Signature.ImageNP", callback: function (object) { object.set('ImageNPname', stringValue); mx.processor.xasAction({ error: function () { logger.error( + "error: error while executing search"); }, actionname: "Signature.signMF", guids: [object.getGUID()] }); };; }); } Can someone point me in the direction of what is lacking or wrong in the code above? or please suggest any other right way to do. Note: In 'stringValue' i have 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAYAAADL1t+KAAAgAElEQVR4Xu2dXaytWVpW5.........' data. I need to save in entity so that later i can retrive the image. If any other way please suggest.   
3 answers

is this the same as:


you may find solution there.


I do not understand exactly why you are doing it like this. Do you want to store the base 64 encoded string as a FileDocument / Image? If so, you should do it not with an input string for a microflow, but with:, fileName + ".jpg", { width: 180, height: 180 }, fileBlob, lang.hitch(this,function() {
	// success: if file document is saved succesfully, also call additional microflow if configured
	if (this.microflow){
}), lang.hitch(this,function(e) { + ": Error occurred attempting to save document: " + e);

The base64 encoded image you can convert to an image with JS with:

var fileBlob = this._b64toBlob(dataUrl.replace("data:image/png;base64,", ""), "image/jpeg");

_b64toBlob : function(b64Data, contentType, sliceSize) {
  contentType = contentType || '';
  sliceSize = sliceSize || 512;

  var byteCharacters = atob(b64Data);
  var byteArrays = [];

  for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
	var slice = byteCharacters.slice(offset, offset + sliceSize);

	var byteNumbers = new Array(slice.length);
	for (var i = 0; i < slice.length; i++) {
	  byteNumbers[i] = slice.charCodeAt(i);

	var byteArray = new Uint8Array(byteNumbers);


  var blob = new Blob(byteArrays, {type: contentType});
  return blob;

Does this help?

Also; please state the Mendix version you are using; the Client API has different functions per version, so could very well be that you / me are referring to changed functions...


Hello Ivo Sturm, I am trying integrating a signature device to mendix application with javascript API, I am calling the javascript by a widget from app store "JavaScriptButton" which is assigning the SRC to IMG inside HTMLSnippetWithContext widget which i got from Appstore. 

The Function from API is as : 

function generateImage() {
    signatureImage = document.getElementById("signatureImage");

    var signatureCanvas = document.createElement("canvas"); = "signatureCanvas";
    signatureCanvas.height = signatureImage.height;
    signatureCanvas.width = signatureImage.width;
    var signatureCtx = signatureCanvas.getContext("2d");

    clearCanvas(signatureCanvas, signatureCtx);
    signatureCtx.lineWidth = 1;
    signatureCtx.strokeStyle = 'blue';
    lastPoint = { "x": 0, "y": 0 };
    isDown = false;
    for (var i = 0; i < m_penData.length; i++) {
        processPoint(m_penData[i], signatureCanvas, signatureCtx);
    signatureImage.src = signatureCanvas.toDataURL("image/jpeg");

    var ImageCode = signatureCanvas.toDataURL("image/jpeg");
    return ImageCode;



In 'ImageCode' i have string / data as  'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAYAAADL1t+KAAAgAElEQVR4Xu2dXaytWVpW5.........' data. I need to save in entity with reference to other field value inside mendix application page. so that later i can retrieve the image.

So, I found some code to return this value to microflow and then from microflow save to entity (as I tried in METHOD 1). But getting empty data in microflow.

I am new to mendix development, Can you please provide the relation between my function generateImage()  above and how I can implement your suggested code? I am using 6.10.2 modeler.

I am waiting for you kind reply.. thank you in advance...