Solved

Concatenate Lookup Field + Drop Down Value to populate a 3rd field using an OnChange Event

Posted on 2011-02-18
10
1,561 Views
Last Modified: 2012-06-22
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.  

 
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();

}

Open in new window


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.  
0
Comment
Question by:2_under_par
  • 7
  • 3
10 Comments
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 34927285
Hi 2_under_par,

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.DataValue = lookupData;

Regards,
Chinmay
0
 

Author Comment

by:2_under_par
ID: 34945713
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"

 
//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;

Open in new window

0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 34945894
instead of

lookupItem.name = crm= crmForm.all.serviceid.DataValue + ' ' + crmForm.all.new_activitydetails.SelectedText ;

Open in new window


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 ;

Open in new window


Regards,
Chinmay

0
 

Author Comment

by:2_under_par
ID: 34946276

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;

Open in new window

0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 34946927
alright

try

lookupItem.name = crmForm.all.new_activitydetails.SelectedText; 

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:2_under_par
ID: 34947237
"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;

Open in new window

0
 

Author Comment

by:2_under_par
ID: 34953336
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.
0
 

Author Comment

by:2_under_par
ID: 34961037
This took care of it.  

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;
     }

Open in new window

0
 

Accepted Solution

by:
2_under_par earned 0 total points
ID: 34961097
I just noticed that for my purpose (implementing this on the Service Activity form) the variable name of customer seems to make no sense.  This was what I actually used.  

http://sites.google.com/site/ranjitclub/working-with-datatypes-in-javascript

 
var service = new Array();
service = null;
service = crmForm.all.serviceid.DataValue;

if (service[0] != null)	
     {
	    crmForm.all.subject.DataValue = crmForm.all.new_activitydetails.SelectedText + ' - ' + service[0].name;
     }

Open in new window

0
 

Author Closing Comment

by:2_under_par
ID: 34995392
The link provided offered a very close solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Sep 22nd 2014 Microsoft released Update Rollup 1 for Microsoft Dynamics CRM 2013 Service Pack 1 and back in July Update Rollup 3 was released.  So we now have:   Update Rollup 1Update Rollup 2Update Rollup 3Service Pack 1Update Rollup 1 for S…
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now