Answered by:
Need help with a very simple OnLoad command

Question
-
Hello All,
I need to make the OnLoad command for a Service Acivity automaticly fill in both the Resrouce and Service.
Can anyone help me with the code?
Thanks, Jay.Friday, July 31, 2009 8:33 PM
Answers
-
Hi,
As both Resources and Service on Service Activity form are lookup type so if you want to hard code Resources and Service ,you need to know GUID of both the resources and service, you can set Resources and service through the following code on form load.
var lookupData = new Array();
//Create an object to add to the array.
var lookupItem= new Object();
//to set service
lookupItem.id="GUID of default service";
lookupItem.typename="service";
lookupItem.name="default service name";
lookupData[0]=lookupItem;
crmForm.all.serviceid.DataValue=lookupData;
//to set resources
lookupItem.id="GUID of default resource";
lookupItem.typename="systemuser";
lookupItem.name="default resource name";
lookupData[0]=lookupItem;
crmForm.all.resources.DataValue=lookupData;
Hope it will help !!!!!
Mahain- Proposed as answer by HIMBAPModerator Monday, August 3, 2009 3:48 PM
- Marked as answer by Jim Glass Jr Monday, August 3, 2009 4:07 PM
Monday, August 3, 2009 3:48 PMModerator
All replies
-
Hi Jay,
I would recommend that you check out the CRM 4.0 SDK client scripting section. Are you harding the Resources and Serivce on the Service Activity form?
Darren Liu | 刘嘉鸿 | MS CRM MVP | English Blog: http://msdynamicscrm-e.blogspot.com | Chinese Blog: http://liudarren.spaces.live.comSaturday, August 1, 2009 4:08 AMModerator -
Hi Jay,
Seems like you want to hard-code the values for Resources and Services.
We need more details to suggest.
Best Regards,
Gagandeep Singh
http://mscrmnovice.blogspot.comSaturday, August 1, 2009 8:00 AM -
I am sorry, I just realized what I wrote is very misleading.
Yes, I intend on hard coding values for Resources and Service on the Service Activity form.
ThanksSaturday, August 1, 2009 12:22 PM -
Hi,
As both Resources and Service on Service Activity form are lookup type so if you want to hard code Resources and Service ,you need to know GUID of both the resources and service, you can set Resources and service through the following code on form load.
var lookupData = new Array();
//Create an object to add to the array.
var lookupItem= new Object();
//to set service
lookupItem.id="GUID of default service";
lookupItem.typename="service";
lookupItem.name="default service name";
lookupData[0]=lookupItem;
crmForm.all.serviceid.DataValue=lookupData;
//to set resources
lookupItem.id="GUID of default resource";
lookupItem.typename="systemuser";
lookupItem.name="default resource name";
lookupData[0]=lookupItem;
crmForm.all.resources.DataValue=lookupData;
Hope it will help !!!!!
Mahain- Proposed as answer by HIMBAPModerator Monday, August 3, 2009 3:48 PM
- Marked as answer by Jim Glass Jr Monday, August 3, 2009 4:07 PM
Monday, August 3, 2009 3:48 PMModerator -
THANK YOU!
It worked great. At first I didnt know how to get the GUID for the items, but I found that clicking the "Send Link" button was great for figuring that out. It also took me alittle while to realize the typename that I needed to use was "equipemnt". I snagged some code from the SDK so that the change was only made when the form was in Create mode. Here is the final form:
var CRM_FORM_TYPE_CREATE = 1;
var CRM_FORM_TYPE_UPDATE = 2;switch (crmForm.FormType)
{
case CRM_FORM_TYPE_CREATE:
var lookupData = new Array();
//Create an object to add to the array.
var lookupItem= new Object();
//to set service
lookupItem.id="{GUID goes here";
lookupItem.typename="service";
lookupItem.name="Field Service";
lookupData[0]=lookupItem;
crmForm.all.serviceid.DataValue=lookupData;//to set resources
lookupItem.id="{GUID goes here}";
lookupItem.typename="equipment";
lookupItem.name="Contractor";
lookupData[0]=lookupItem;
crmForm.all.resources.DataValue=lookupData;
break;case CRM_FORM_TYPE_UPDATE:
break;
}Tuesday, August 4, 2009 8:30 PM