CRC string for QRcode

0
are there anyway to convert a string into CRC in medix? any help would be nice. thanks in advance
asked
1 answers
2

Assuming that you mean a 32bit checksum could be like this;

 

1 – add a new java action with a string input called String

2 – choose to return a String in java action

3 – paste the below code (after deploying to eclipse, in eclipse), replace x with your module name

// This file was generated by Mendix Modeler.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.

package x.actions;

import java.util.zip.CRC32;
import java.util.zip.Checksum;

import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;

/**
 * 
 */
public class StringToCRC32 extends CustomJavaAction<String>
{
	private String String;

	public StringToCRC32(IContext context, String String)
	{
		super(context);
		this.String = String;
	}

	@Override
	public String executeAction() throws Exception
	{
		// BEGIN USER CODE
        byte[] bytes = String.getBytes();
        Checksum checksum = new CRC32(); // java.util.zip.CRC32
        checksum.update(bytes, 0, bytes.length);
        return Long.toString((checksum.getValue()));
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 */
	@Override
	public String toString()
	{
		return "StringToCRC32";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

4 – use the java action in your microflow



 

answered