jlblanke
asked on
I want to autopopulate Service Name on the serviceappointment entity
I created an OnLoad Script based on some other scripts that Experts Exchange has helped me with.
I want to add a default service name to the service activity form to expedite scheduling. It is not pasting in the service name (“Schedule”). I am not getting any errors either OnLoad or OnSave.
What did I leave out? Here is the code:
= = = = = = = = = = =
function LoadServiceName()
{
var oService = Xrm.Page.getAttribute('ser viceid');
var lookupData = new Array();
lookupData[0] = new Object();
lookupData[0].name = 'Schedule';
lookupData[0].entityType = 'service';
// check that the field exists and contains a value to avoid errors
if (oService != null && oService.getValue() != null) {
// set Service Activity Service to Schedule
Xrm.Page.getAttribute("ser viceid").s etValue(lo okupData);
}
}
I want to add a default service name to the service activity form to expedite scheduling. It is not pasting in the service name (“Schedule”). I am not getting any errors either OnLoad or OnSave.
What did I leave out? Here is the code:
= = = = = = = = = = =
function LoadServiceName()
{
var oService = Xrm.Page.getAttribute('ser
var lookupData = new Array();
lookupData[0] = new Object();
lookupData[0].name = 'Schedule';
lookupData[0].entityType = 'service';
// check that the field exists and contains a value to avoid errors
if (oService != null && oService.getValue() != null) {
// set Service Activity Service to Schedule
Xrm.Page.getAttribute("ser
}
}
ASKER
Thanks! I added the GUID but it is still not copying in the service name. What am I missing? :(
Here is the revised script:
function LoadServiceName()
{
var oService = Xrm.Page.getAttribute('ser viceid');
var lookupData = new Array();
lookupData[0] = new Object();
lookupData[0].id = '{690001d1-0be3-e111-a141- 0050569800 0e}';
lookupData[0].name = 'Schedule';
lookupData[0].entityType = 'service';
// check that the field exists and contains a value to avoid errors
if (oService != null && oService.getValue() != null) {
// set Service Activity Service to Schedule
Xrm.Page.getAttribute("ser viceid").s etValue(lo okupData);
}
}
Here is the revised script:
function LoadServiceName()
{
var oService = Xrm.Page.getAttribute('ser
var lookupData = new Array();
lookupData[0] = new Object();
lookupData[0].id = '{690001d1-0be3-e111-a141-
lookupData[0].name = 'Schedule';
lookupData[0].entityType = 'service';
// check that the field exists and contains a value to avoid errors
if (oService != null && oService.getValue() != null) {
// set Service Activity Service to Schedule
Xrm.Page.getAttribute("ser
}
}
Have you added the Event Handler on the form?
Can you add an alert to the if condition to make sure that its getting called?
Can you add an alert to the if condition to make sure that its getting called?
if (oService != null && oService.getValue() != null) {
// set Service Activity Service to Schedule
Xrm.Page.getAttribute("serviceid").setValue(lookupData);
alert("Test!");
}
ASKER
I added the alert. It did not show up when I first opened the form.
Then I manually added the service and did a save and close. When I reopened the form I received the alert even though the field had the data in it.
Then I manually added the service and did a save and close. When I reopened the form I received the alert even though the field had the data in it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I removed the first part of the if statement (oService != null) and changed the second part (oService == null).
Now when I open a new service activity form I get the alert. Nothing gets copied into the Service name field.
Now when I open a new service activity form I get the alert. Nothing gets copied into the Service name field.
I've tested it without the second part and it seems to work OK.
The only difference is obviously the GUID and the name, can you confirm that the service type you are adding has a name of Schedule and that the GUID is correct?
The only difference is obviously the GUID and the name, can you confirm that the service type you are adding has a name of Schedule and that the GUID is correct?
ASKER
I have attached the advanced find query I used to get the GUID. I am puzzled.
For-Re-import---Services-Advance.xlsx
For-Re-import---Services-Advance.xlsx
ASKER
It's working now! Not sure why. Unless there is a web server refresh that has to occur.
ASKER
Thanks for working with me on this. It is working now. Not sure why it started working - maybe a refresh delay between my office and where the webserver resides (?). At any rate it is now doing what I want it to do. Thanks for helping me with this problem and proofing my script. :)
lookupData[0].id = GUID.