Link to home
Start Free TrialLog in
Avatar of jlblanke
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('serviceid');

      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("serviceid").setValue(lookupData);
    }  
}
Avatar of 50cal
50cal
Flag of United Kingdom of Great Britain and Northern Ireland image

Your not specifying the ID (GUID) of the lookup value.

lookupData[0].id = GUID.
Avatar of jlblanke
jlblanke

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

      var lookupData = new Array();
           lookupData[0] = new Object();
           lookupData[0].id = '{690001d1-0be3-e111-a141-00505698000e}';
           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("serviceid").setValue(lookupData);
    }  
}
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?
if (oService != null && oService.getValue() != null) {
        // set Service Activity Service to Schedule
         Xrm.Page.getAttribute("serviceid").setValue(lookupData);
        alert("Test!");
    }  

Open in new window

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.
ASKER CERTIFIED SOLUTION
Avatar of 50cal
50cal
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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?
I have attached the advanced find query I used to get the GUID. I am puzzled.
For-Re-import---Services-Advance.xlsx
It's working now! Not sure why. Unless there is a web server refresh that has to occur.
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. :)