Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Create a Service Order through class for custom Table.

(0) ShareShare
ReportReport
Posted on by 31

i want to create a service order through service request i have a form "service request form" which has three data sources ServiceRequestTable,ServiceRequestLines,ServiceRequestQuotationLines. now similarly i also created a custom form call "serviceorder form"

which also has three data sources SalesOrderTable,SalesOrderLines,SalesOrderQuotationLines. now when i created a request for serviceOrder i want to create a service order through that request that is why i added custom button called " Create Service order" in action pane of a service request form now i want when i click that button it creates ServiceOrder and get all the data of a current Service Request. i tried the code below in class for creating the service order but it is not working. 

class CreateServiceOrder
{
ServiceOrderRequestId serviceOrderRequestId;

ServiceOrderRequestId parmServiceOrderRequestId(ServiceOrderRequestId _serviceOrderRequestId = serviceOrderRequestId)
{
serviceOrderRequestId = _serviceOrderRequestId;
return serviceOrderRequestId;
}

void run()
{
//declaring variables
ServiceOrderTable serviceOrderTable;
ServiceOrderQuotationLines serviceOrderQuotationLines;
ServiceOrderLines serviceOrderLines;
ServiceRequestTable serviceRequestTable;
ServiceRequestLines serviceRequestLines;
ServiceRequestQuotationLines serviceRequestQuotationLines;
Args args;
FormRun formRun;
NumberSeq numberSeq;

ttsBegin;
//creating sales order header
//getting sales order id from number sequence

numberSeq = NumberSeq::newGetNum(SMAParameters::numRefServiceOrderId());
numberSeq.used();
serviceOrderTable.ServiceOrder = numberSeq.num();
serviceOrderTable.initValue();
serviceOrderTable.RequestId = serviceOrderRequestId;
serviceOrderTable.CustAccount = custAccount;

//////validate

if (!serviceOrderTable.validateWrite())
{
throw Exception::Error;

}
serviceOrderTable.insert();
//creating sales order line
serviceOrderLines.initValue();
serviceOrderLines.ItemId = serviceRequestLines.ItemId;
serviceOrderLines.Qty = serviceRequestLines.Qty;
serviceOrderLines.insert();

serviceOrderQuotationLines.initValue();
serviceOrderQuotationLines.SMATransactionType = serviceRequestQuotationLines.SMATransactionType;
serviceOrderQuotationLines.Worker = serviceRequestQuotationLines.Worker;
serviceOrderQuotationLines.insert();

ttsCommit;
}

}

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,550 Super User 2024 Season 1 on at
    RE: Create a Service Order through class for custom Table.

    Hi Munib, Are you getting any error or have you debugged the code. Please provide more information on issue when you say it's not working.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,684 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,414 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans