Create Service order using code.

Hi,

How can i create a service order using X++ in AX 2012.

Please guide me.

thanks in Advance,

Mani.

Moved to developer forum. Please post the development related questions in developer forum.

For code reference, look at \Classes\SMAServiceOrderCreate

thanks for reply Kranthi,

But, i am not able to create properly. Please help me .

thanks,

Mani

What issue do you have? Can you show us the code?

Hi Kranti, there is no standard code; I just trying with the job to create service order, So its updating only the header part not the line part.

Here is my code:

static void JobServiceOrder(Args _args)
{
SMAServiceOrderTable SMAServiceOrdertable;
SMAServiceOrderLine SMAServiceOrderline;
;

ttsBegin;

SMAServiceOrdertable.ServiceOrderId=‘00059’;
SMAServiceOrdertable.custAccount=‘025’;
SMAServiceOrdertable.ProjId=‘000058’;
SMAServiceOrdertable.Description=‘WiFi setup repair’;
SMAServiceOrdertable.AgreementId=“00001”;
SMAServiceOrdertable.ServiceAddressName =“OakCompany”;
SMAServiceOrdertable.insert();

SMAServiceOrderline.ProjCategoryId=“Car Audio”;
SMAServiceOrderline.ServiceObjectRelationId=“000021”;
SMAServiceOrderline.ServiceObjectId=“000002”;
SMAServiceOrderline.ServiceTaskId=“Inspector”;
SMAServiceOrderline.insert();
info(“work finished”);
ttsCommit;

}

And, I attached the Screenshot below: so here I want to update line field also.What should i do/edit in above job OR the other way.

Please advice me. Thanks.

You are not setting this on service order line. Try adding below lines and also check if the InventDimId is filled on SMAServiceOrderline table.

SMAServiceOrderline.ServiceOrderId = SMAServiceOrdertable.ServiceOrderId;
SMAServiceOrderline.initFromServiceOrder(SMAServiceOrdertable.ServiceOrderId);

hi Kranthi, I have done whatever u told.

I added the InventDimId in SMAServiceorderlineTable and also added the above two lines in my code.But till now only the header part is updated, line part remains blank. what should i do now. please advice me.

Thanks

Can you show your final code?

Hi Kranthi, this is the final code:

static void JobServiceOrder(Args _args)
{
SMAServiceOrderTable SMAServiceOrdertable;
SMAServiceOrderLine SMAServiceOrderline;
;

ttsBegin;

SMAServiceOrdertable.ServiceOrderId=‘00066’;
SMAServiceOrdertable.custAccount=‘025’;
SMAServiceOrdertable.ProjId=‘000058’;
SMAServiceOrdertable.Description=‘WiFi setup repair’;
SMAServiceOrdertable.AgreementId=“00001”;
SMAServiceOrdertable.ServiceAddressName =“OakCompany”;
SMAServiceOrdertable.insert();

SMAServiceOrderline.ServiceOrderId = ‘00066’;
SMAServiceOrderline.ProjCategoryId=“Car Audio”;
SMAServiceOrderline.ServiceObjectRelationId=“000021”;
SMAServiceOrderline.ServiceObjectId=“000002”;
SMAServiceOrderline.ServiceTaskId=“Inspector”;
SMAServiceOrderline.insert();
SMAServiceOrderline.ServiceOrderId = SMAServiceOrdertable.ServiceOrderId;
SMAServiceOrderline.initFromServiceOrder(SMAServiceOrdertable.ServiceOrderId);
info(“work finished”);
ttsCommit;

}

Thanks.

Code after insert will not work, try below.

SMAServiceOrderline.ServiceOrderId = ‘00066’;
SMAServiceOrderline.initFromServiceOrder(SMAServiceOrdertable.ServiceOrderId);
SMAServiceOrderline.ProjCategoryId=“Car Audio”;
SMAServiceOrderline.ServiceObjectRelationId=“000021”;
SMAServiceOrderline.ServiceObjectId=“000002”;
SMAServiceOrderline.ServiceTaskId=“Inspector”;
SMAServiceOrderline.insert();

info(“work finished”);

Hi kranthi,

I was trying it from last week,now its done with the help of you.

Thank you so much.

Mani.