web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Field Service forum / Fail to create workorder
Field Service forum

Fail to create workorder

(0) ShareShare
ReportReport
Posted on by

Hi all,

I have an issue when create a workorder.

it have log an error "The Service Account is required."

Do anyone have idea on my below code? 

private void CreateWorkOrder(IOrganizationService service, ITracingService tracer)
{
	tracer.Trace(String.Format("{0} : {1}", MethodBase.GetCurrentMethod().Name, "Start CreateWorkOrder function"));
	var workOrder = new Entities.msdyn_workorder();

	workOrder.msdyn_name = "Test000001";
	workOrder.smsmt_SurveyCompleted = false;
	workOrder.msdyn_ServiceAccount = oLead.ParentAccountId;
	workOrder.msdyn_ReportedByContact = oLead.ParentContactId;
	workOrder.smsmt_ValuableInformationSharedwithInteract = oLead.smsmt_ValuableInformationSharedwithInteract;
	workOrder.OwnerId = new EntityReference(Entities.SystemUser.EntityLogicalName, this.Context.UserId);
	tracer.Trace(String.Format("{0} : {1}", MethodBase.GetCurrentMethod().Name, "assign passed"));

	var Guid = service.Create(workOrder);
	tracer.Trace(String.Format("{0} : {1}", MethodBase.GetCurrentMethod().Name, $"Work Order Created with Id: {Guid}"));

}

This function is added in PostUpdate.
Setting.PNG

Thanks,

G.K

Categories:
  • Fannie30 Profile Picture
    2,990 Moderator on at

    This is a custom plugin I presume?  

  • Fannie30 Profile Picture
    2,990 Moderator on at

    What is it the plugin is trying to do?

  • Community Member Profile Picture
    on at

    Thanks your reply.

    Yes. I want to auto create a workorder by after a lead completed.

  • Dynamics365 Rocker Profile Picture
    7,755 on at

    Make sure that a user updating lead also have Create, Read and Update privilege on Work Order entity.

  • Community Member Profile Picture
    on at

    Did the privilege is not related with user? is related with lead??

  • Verified answer
    Al Iggs Profile Picture
    Microsoft Employee on at

    This might be a silly question, but does your lead actually have an account associated? Lead.ParentAccountId is not mandatory and by default not even on the form. Btw, have you considered workflow or Flow instead of writing a plugin?

  • Fannie30 Profile Picture
    2,990 Moderator on at

    Personally, I would go to the route of using Microsoft Flow..  I also agree with Alexander, since Lead doesn't require account, and it's not on the form, you may run into a multitude of issues.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Field Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans