web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)
New Discussion

Populate a Contact Lookup Field from a QR Code Value

(0) ShareShare
ReportReport
Posted on by

I've seen several posts about populating lookup fields using a QR code field value (such as a GUID). I had to find a way to populate a Contact lookup field using a QR Code as a means to take attendance at an event...1:N relationship from the custom event entity to contacts. I was using Google's QR Generator API to dynamically create unique QR Codes that are linked to from a customer service portal. Google's API for QR Generation can be accessed by using:

chart.googleapis.com/chart value you want to encode]

I found that most suggested answers for accomplishing the lookup field population involved a now deprecated HTTP Request function to perform a lookup action on the CRM (also involved using additional SDK libraries). In my case, however, I was able to completely bypass the use of an HTTP Request and additional libraries and instead directly set the necessary lookup field attributes: contact ID, contact display name (i.e. "John Smith"), and entity type (contact). Here is my custom JavaScript:

function QRValue_OnChange() {
var qrvalue = Xrm.Page.getAttribute("demo_attendeeqrvalue").getValue(); // the QR value
var splitqr;
if(qrvalue) {
splitqr=qrvalue.split("&");
setLookupValue(splitqr[0].replace("%20"," "),splitqr[1]);
}
}

function setLookupValue(lookupName, lookupId) {
var lookupData = new Array();
var lookupItem = new Object();
lookupItem.id = lookupId;
lookupItem.name = lookupName;
lookupItem.entityType = "contact";
lookupData[0] = lookupItem;
Xrm.Page.getAttribute("demo_attendee").setValue(lookupData); // the lookup field to populate
}

In this case, I encoded the contact's name followed by an ampersand (&) and then the contact's unique id. I used the & symbol as a means to later split the QR code into contact name and contact ID before passing the parameters to the lookup field set function. (I have a replace function call because spaces are usually encoded as '%20' in URLs.) This JS file runs onChange() of the QR field (Google how to set up a custom JS Web Resource File on a form). This strategy worked like a charm for our needs. Hope this helps someone! Let me know if it does so I can feel good :)

*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans