Hi
Is there any possibility to copy the text feild value to lookup feild using javascript or workflow ?
*This post is locked for comments
Hi
Is there any possibility to copy the text feild value to lookup feild using javascript or workflow ?
*This post is locked for comments
Will this work with CRM 2011?
And how would you do this as a workflow?
OK. But where does the link between them reside.
Basically for this to work, your lookup entity (class code), would need to have a text field that contains the data for Class Id, so that you can retrieve the data.
The above sample shows you how to do that.
If you need to create the class/class code record, you will need to add additional logic to handle create.
My answer above still applies. You will have to modify this to handles your own logic, but it should work.
Don't forget to add a SDK.REST.js to your solution and to the form where you are calling this from.
Good luck.
Hi Aric ,
I have entity called new_student
In that entity i have two feilds called lookup feild (class code )and single line of text (class id). If i enter the value in text field it should autopopulate the lookup field using javascript
Thanks
So, do you have an entity called class codes?
How do you know what to put in the class code field based on class id?
Are you planning to create a new record in the class code entity, or retrieve an existing value?
As you are using CRM 2013, you can use SDK.REST API functions to retrieve or create values from the Class Code entity.
My first suggestion is that you download the CRM Rest Builder by Jason Lattimer:
Create a Request to Retrieve Multiple using the 2011 Endpoint (as you are using CRM 2013).
Select your Primary Entity (new_ClassCode), select the Id and the name from the Fields to Select (this is in order to set the value in the lookup), in the Filter select new_ClassCode from the Entity, and select the attribute, eq and the value from your text box.
Click on Create Request to Generate the Code:
The following is the Generated Code, which I added to a function (assume new_ClassCode is the lookup entity name), the function to set the Lookup and the OnChange event done on the text box control:
function text_classid_onchange()
{
var textValue = Xrm.Page.getAttribute("new_classid").getValue();
GetLookupValue(textValue);
}
function GetLookupValue(classId)
{
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/new_ClassCodeSet?$select=new_ClassCodeId,new_Name&$filter=new_ClassId eq '" + classId + "'", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
var returned = JSON.parse(this.responseText).d;
var results = returned.results;
for (var i = 0; i < results.length; i++) {
var classCodeId = results[i].new_ClassCodeId;
var name = results[i].new_Name;
SetLookupValue("new_classcodeid", classCodeId, name, "new_classcode");
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
function setLookupValue(fieldName, lookupId, lookupName, entityName)
{
var lookupData = new Array();
var lookupItem = new Object();
lookupItem.id = lookupId;
lookupItem.name = lookupName;
lookupItem.entityType = entityName;
lookupData[0] = lookupItem;
Xrm.Page.getAttribute(fieldName).setValue(lookupData);
}
If you make the required changes to this, and use CRM Rest Builder, you should be able to achieve your results.
Hope this helps.
Hi syed , Thanks for the reply
I have an entity called student. In that entity i have 2 fields called class id and class code where class id is the single line text and class code is the lookup field . If i enter the value in class id (single line text )it should auto populate the lookup field which is class code . I need javascript for this scenerio. I tried to do with workflow but its not work for me , is there any idea please share it.
Thanks,
Yes we can copy text field value and create lookup records using both js and workflow .Can you pls provide more details what you are looking for.
Try the below sample
// define the data to create new account
Var lookuptext =Xrm.page.getAttribute("new_customTextField").getValue();
var data =
{
"name": lookuptext
}
// create account record
Xrm.WebApi.createRecord("account", data).then(
function success(result) {
console.log("Account created with ID: " + result.id);
// perform operations on record creation
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
Hope this helps
André Arnaud de Cal...
292,492
Super User 2025 Season 1
Martin Dráb
231,305
Most Valuable Professional
nmaenpaa
101,156