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

Community site session details

Session Id :
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;
}

}

I have the same question (0)
  • Mohit Rampal Profile Picture
    12,563 Moderator 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 701 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 588 Most Valuable Professional

#3
Sumit Singh Profile Picture

Sumit Singh 544

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans