2_under_par
asked on
Concatenate Lookup Field + Drop Down Value to populate a 3rd field using an OnChange Event
Good Day Experts,
Previously, I had a Read Only field (Subject on Service Activity Form) which was populated by 2 different drop down fields. An OnChange Event triggered this and all was fine. Now, I need to concatenante a Lookup Field (Service) + a drop down value (new_activitydetails) to populate the Subject in the same manner. Problem is, the Subject continues to be populated with "[object Object]" for the value of the Service field.
I might be barking up the wrong tree here, but I thought I read something about using an Array to grab the Service Lookup Field. This is what I came up with, but its still not working.
So, when finished, I need to grab this value and Concatenante it to the new_activitydetails drop down value. Any advice would be greatly appreciated.
Previously, I had a Read Only field (Subject on Service Activity Form) which was populated by 2 different drop down fields. An OnChange Event triggered this and all was fine. Now, I need to concatenante a Lookup Field (Service) + a drop down value (new_activitydetails) to populate the Subject in the same manner. Problem is, the Subject continues to be populated with "[object Object]" for the value of the Service field.
I might be barking up the wrong tree here, but I thought I read something about using an Array to grab the Service Lookup Field. This is what I came up with, but its still not working.
var lookupItem = new Array;
lookupItem = crmForm.all.serviceid.DataValue;
if (lookupItem[0] != null)
{
var conn_str = "Provider=SQLOLEDB.1;Initial Catalog=MSCRM;Data Source=SQLSERVER;User Id=sa;Password=access321";
var conn = new ActiveXObject("ADODB.Connection");
var rs = new ActiveXObject("ADODB.Recordset");
var adOpenDynamic = 2;
var adLockOptimistic = 3;
var query = "SELECT IsNull(Name,'') Name
FROM ServiceBase
WHERE ServiceId='" + lookupItem[0].id + "' ";
conn.open(conn_str, "", "");
rs.open(query, conn, adOpenDynamic, adLockOptimistic);
if(!rs.bof && !rs.eof)
{
var aStr1 = new String(rs(0));
crmForm.all.subject.DataValue = aStr1.toString();
}
rs.close();
conn.close();
}
So, when finished, I need to grab this value and Concatenante it to the new_activitydetails drop down value. Any advice would be greatly appreciated.
ASKER
I have next to no experience with arrays, so this is a shot in the dark...
I get a pop up "This control only accepts strings or null as an input"
I get a pop up "This control only accepts strings or null as an input"
//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = crmForm.all.serviceid.DataValue;
lookupItem.typename = 'subject';
lookupItem.name = crm= crmForm.all.serviceid.DataValue + ' ' + crmForm.all.new_activitydetails.SelectedText ;
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
crmForm.all.subject.DataValue = lookupData;
instead of
try
ServiceId is also an array so you will have to access it in this way
Regards,
Chinmay
lookupItem.name = crm= crmForm.all.serviceid.DataValue + ' ' + crmForm.all.new_activitydetails.SelectedText ;
try
ServiceId is also an array so you will have to access it in this way
lookupItem.name = crmForm.all.serviceid.DataValue[0].name + ' ' + crmForm.all.new_activitydetails.SelectedText ;
Regards,
Chinmay
ASKER
I definately had a typo in there. After updating to reflect the code below, I am still getting this error... "This control only accepts strings or null as an input"
//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = crmForm.all.serviceid.DataValue;
lookupItem.typename = 'subject';
lookupItem.name = crmForm.all.serviceid.DataValue[0].name + ' ' + crmForm.all.new_activitydetails.SelectedText;
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
crmForm.all.subject.DataValue = lookupData;
alright
try
try
lookupItem.name = crmForm.all.new_activitydetails.SelectedText;
ASKER
"This control only accepts strings or null as an input" is the error I'm still getting.
//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = crmForm.all.serviceid.DataValue;
lookupItem.typename = 'subject';
lookupItem.name = crmForm.all.new_activitydetails.SelectedText;
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
crmForm.all.subject.DataValue = lookupData;
ASKER
At this point, if I could just get the <serviceid> copied to the <subject>, within the OnChange event of the <serviceid>, I could probably figure the rest out.
ASKER
This took care of it.
http://sites.google.com/site/ranjitclub/working-with-datatypes-in-javascript
http://sites.google.com/site/ranjitclub/working-with-datatypes-in-javascript
var customer = new Array();
customer = null;
customer = crmForm.all.serviceid.DataValue;
if (customer[0] != null)
{
crmForm.all.subject.DataValue = crmForm.all.new_activitydetails.SelectedText + ' - ' + customer[0].name;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The link provided offered a very close solution.
First of all.. Whoa.... I would suggest using CRM Web Services to fetch data from the CRM[even though it is slow]. now coming to the point. Subject field is not something static that you can populate it like this. It must be present in CRM database and then and only you will be able to do it. If you just need to "show" the field in that case you will have to grab the reference to the subject field and then use the following code
//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = '{actual guid}';
lookupItem.typename = 'subject';
lookupItem.name = 'subject text';[Here you will do the string concate]
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
crmForm.all.subject.DataVa
Regards,
Chinmay